![]() ![]() You can make a Trait MutiPrimaryKey, then extend the getKey and find method: 1) In App\Classes\Database create he following file MultiPrimaryKey. This method accepts an array of attributes or a single attribute: users->append('team') users->append( 'team', 'isadmin') contains (key, operator null, value null) The contains method may be used to determine if a given model instance is contained by the collection. data->save () data->id Can be used like this. As usual with my questions, the answer is probably super easy, yet I can't seem to find it right now. 101 There's findOrFail () method which throws 404 if nothing was found, e.g. 555 After save, data->id should be the last id inserted. ( ::find($reportElement) ), not for the group_id. This obviously doesn't work as anticipated, as it only looks for the id My current code for this route is: public function showReports ($id)įoreach ($group->getLatestReports(20) as $reportElement) ![]() If they don't exist, I want to create them. When visiting one of my pages, I want to fetch the latest records from my external data source and match them with the corresponding database rows. 1 Answer Sorted by: 25 In your controller you are always going to search by id as your Eloquent query uses: authorModel Authors::find (id) As your named route can be supplied with an int or string (:any) run a type check in the controller on id and run a different query based on the result. id is also not auto-increasing, as it's an external id I'm using for easier internal processing.Įach external id can be present for every of my groups once and have a different score for each of them, hence the composite primary key. The primary key of this table is a composite of id and group_id. Group_id is a foreign key referencing the groups table. The database table reports has the following schema: | id | group_id | score |. Currently however I'm running into some troubles regarding on of my Eloquent models. So far everything's been completely straight-forward and it's just great to work with it. I've recently started working with Laravel 5 as a framework. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |