Guest User

Untitled

a guest
Nov 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. Post
  2. subject
  3. body
  4. source_id
  5. status_id
  6.  
  7. Status
  8. id
  9. label
  10. other_field
  11.  
  12. Source
  13. id
  14. label
  15. other_field
  16.  
  17.  
  18. View
  19. create view read_only_posts as
  20. SELECT statuses.label as status, sources.label as source, posts.*
  21. from posts
  22. left join statuses on statuses.id = posts.status_id
  23. left join sources on sources.id = posts.source_id
  24.  
  25. // Post.php
  26. class Post extends Model
  27. {
  28. //
  29. }
  30.  
  31. // ReadOnlyPost.php
  32. class ReadOnlyPost extends Post
  33. {
  34. protected $table = 'read_only_posts';
  35. }
  36.  
  37. // Post.php Model
  38. public function tags()
  39. {
  40. return $this->morphToMany(Tag::class, 'taggable');
  41. }
  42.  
  43. // AppServiceProvider
  44. public function boot()
  45. {
  46. Relation::morphMap([
  47. 'properties' => Post::class,
  48. 'properties' => ReadOnlyPost::class, <--- Can't do this
Add Comment
Please, Sign In to add comment