How can I add, delete and get a favorite from product with polymorphic relationship, in Laravel 5.6?
问题 My product model like this : <?php ... class Product extends Model { ... protected $fillable = ['name','photo','description',...]; public function favorites(){ return $this->morphMany(Favorite::class, 'favoritable'); } } My favorite model like this : <?php ... class Favorite extends Model { ... protected $fillable = ['user_id', 'favoritable_id', 'favoritable_type']; public function favoritable() { return $this->morphTo(); } } My eloquent query laravel to add, delete and get like this : public