laravel-favorite
laravel-favorite copied to clipboard
Missing id column in default favorites table migration
Missing column id
in default favorites table migration
when i try to add some model to favorites it generates following query, which requires id
column
SQL: insert into "favorites" ("user_id", "favoriteable_id", "favoriteable_type", "updated_at", "created_at") values (1, 2, App\Models\Institution\Institution, 2021-04-19 06:19:59, 2021-04-19 06:19:59) returning "id"
i dont really realize why and where this is happening, i guess it has something to do with relationtship registration
Possible implementation
add id column to default migration, or figure out why eloquent adds requiring "id"
to its query and get rid of it
My environment
- php 7.4
- laravel 8.36.2
im not the only one who has this issue, see #13
ok so I found out those code in eloquent:
// If the model has an incrementing key, we can use the "insertGetId" method on
// the query builder, which will give us back the final inserted ID for this
// table from the database. Not all tables have to be incrementing though.
$attributes = $this->getAttributes();
if ($this->getIncrementing()) {
$this->insertAndSetId($query, $attributes);
}
seems like we need to add this code to Favorite
model
public function getIncrementing()
{
return null;
}
ill add pr shortly
App\Models\Course::isFavorited must return a relationship instance. (View: E:\laragon\www\Courses\resources\views\admin\courses\show.blade.php)
What is the solution to this error?
Hey, have you resolved your problem?