Many To Many Polymorphic Relations (Model Structure)
https://viblo.asia/p/eloquent-relationships-in-laravel-phan-2-aRBvXWEokWE
Model Structure
Tiếp theo, chúng ta đã sẵn sàng để xác định các mối quan hệ trên model. Các Post
model và Video
model cả hai sẽ có một tags
method gọi phương thức morphToMany
trên lớp base Eloquent:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* Get all of the tags for the post.
*/
public function tags()
{
return $this->morphToMany('App\Tag', 'taggable');
}
}
PreviousMany To Many Polymorphic Relations (Table Structure)NextMany To Many Polymorphic Relations (Defining The Inverse Of The Relationship)
Last updated
Was this helpful?