Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. title
  2. description
  3. seoble_id
  4. seoble_type
  5. timestamps
  6.  
  7. namespace AppModels;
  8.  
  9. class Post extends Eloquent {
  10. public function seo()
  11. {
  12. return $this->morphOne('AppModelsSeo', 'seoble');
  13. }
  14. }
  15.  
  16. title
  17. description
  18. object_id
  19. type
  20. timestamps
  21.  
  22. namespace AppModels;
  23.  
  24. class Post extends Eloquent {
  25. public function seo()
  26. {
  27. return $this->hasOne('AppModelsSeo', 'object_id')->where('type', 'post');
  28. }
  29. }
  30.  
  31. namespace AppModels;
  32.  
  33. class Seo extends Eloquent {
  34.  
  35. public function seoable()
  36. {
  37. return $this->morphTo();
  38. }
  39.  
  40. public function post()
  41. {
  42. return $this->belongsTo('AppModelsSeo', 'seoable_id');
  43. }
  44. }
  45.  
  46. /*----*/
  47.  
  48. namespace AppModels;
  49.  
  50. class Post extends Eloquent {
  51.  
  52. public function getSeo($type)
  53. {
  54. return $this->morphOne('AppModelsSeo', 'seoable');
  55. }
  56. }
  57.  
  58.  
  59. // you can using like this :
  60. $seo = Seo::where('seoable_type', 'post');
  61. $seo->post->first();
  62.  
  63. // or like this :
  64. $post = Post::with('getSeo')->findOrFail($id)->toArray();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement