Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class Category extends Model
  2. {
  3. protected $table = 'categories';
  4.  
  5. public function pharmacies()
  6. {
  7. return $this->belongsToMany(Pharmacy::class, 'pharmacy_category', 'category_id', 'id');
  8. }
  9.  
  10. public function medicines()
  11. {
  12. return $this->hasMany(Medicine::class);
  13. }
  14. }
  15.  
  16. class Pharmacy extends Model
  17. {
  18. use SoftDeletes;
  19. protected $table = 'pharmacies';
  20.  
  21. protected $appends = ['favourite'];
  22.  
  23. public function categories()
  24. {
  25. return $this->belongsToMany(Category::class,'pharmacy_category','pharmacy_id','id');
  26. }
  27.  
  28. public function getFavouriteAttribute()
  29. {
  30. if (!Auth::check()) {
  31. return 0;
  32. }
  33. return (FavouritePharmacy::where('user_id', Auth::user()->id)->where('pharmacy_id', $this->id)->count() == 1) ? 1 : 0;
  34. }
  35. }
  36.  
  37. class Medicine extends Model
  38. {
  39.  
  40. protected $appends = ['favourite'];
  41.  
  42. public function orders()
  43. {
  44. return $this->belongsToMany(Order::class);
  45. }
  46.  
  47. public function getFavouriteAttribute()
  48. {
  49. if (!Auth::check()) {
  50. return 0;
  51. }
  52. return (FavouriteMedicine::where('user_id', Auth::user()->id)->where('medicine_id', $this->id)->count() == 1) ? 1 : 0;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement