Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- title
- description
- seoble_id
- seoble_type
- timestamps
- namespace AppModels;
- class Post extends Eloquent {
- public function seo()
- {
- return $this->morphOne('AppModelsSeo', 'seoble');
- }
- }
- title
- description
- object_id
- type
- timestamps
- namespace AppModels;
- class Post extends Eloquent {
- public function seo()
- {
- return $this->hasOne('AppModelsSeo', 'object_id')->where('type', 'post');
- }
- }
- namespace AppModels;
- class Seo extends Eloquent {
- public function seoable()
- {
- return $this->morphTo();
- }
- public function post()
- {
- return $this->belongsTo('AppModelsSeo', 'seoable_id');
- }
- }
- /*----*/
- namespace AppModels;
- class Post extends Eloquent {
- public function getSeo($type)
- {
- return $this->morphOne('AppModelsSeo', 'seoable');
- }
- }
- // you can using like this :
- $seo = Seo::where('seoable_type', 'post');
- $seo->post->first();
- // or like this :
- $post = Post::with('getSeo')->findOrFail($id)->toArray();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement