determine which type of owning model to return when accessing the imageable relation.
To get all of the functionality of a full User model object (such as firstOrCreate()) then you have to call them on the model object. Eloquent assumes the foreign key of the relationship based on the model. All Eloquent models extend Illuminate\Database\Eloquent\Model. The relationship object has a create() method and a save() method, however the relationship object is not a full model object. Models typically live in the app directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json file. So, in this case, Eloquent assumes that the Phone model has a userid column. Eloquent determines the foreign key name by examining the name of the relationship method and suffixing the method name with id.
To get started, create an Eloquent model. When invoking the user method, Eloquent will attempt to find a User model that has an id which matches the userid column on the Phone model. Each database table has a corresponding 'Model' which is used to interact with that table.īefore getting started, be sure to configure a database connection in config/database.php. The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database.