You answered it yourself :) The only difference is create persists to the database whereas make just returns a new instance of the model
Dec 7, 2018
10
Level 2
Create vs Make for models?
In php artisan tinker when i use the create vs make methods for a model, an attribute defauls to 0 for create but is created correctly when I use the make method. I took at the source code and create essentially calls make and then saves the data to the database.
Any guidance would be appreciated?
>>> factory('App\Renter')->make();
=> App\Renter {#3037
student_id: 70606910, <----------
fname: "Wanda",
lname: "Glover",
email: "[email protected]",
}
>>> factory('App\Renter')->create();
=> App\Renter {#3033
student_id: 0, <----------
fname: "Dorothea",
lname: "Lueilwitz",
email: "[email protected]",
}
>>>
Level 44
@BINIYAM20 - Is student_id the primary key? I've seen this happen when you have a primary key that isn't auto incrementing. To fix it you just have to put this in your Renter model:
...
public $incrementing = false;
...
Please or to participate in this conversation.