Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Category extends Model
- {
- protected $table = 'categories';
- public function pharmacies()
- {
- return $this->belongsToMany(Pharmacy::class, 'pharmacy_category', 'category_id', 'id');
- }
- public function medicines()
- {
- return $this->hasMany(Medicine::class);
- }
- }
- class Pharmacy extends Model
- {
- use SoftDeletes;
- protected $table = 'pharmacies';
- protected $appends = ['favourite'];
- public function categories()
- {
- return $this->belongsToMany(Category::class,'pharmacy_category','pharmacy_id','id');
- }
- public function getFavouriteAttribute()
- {
- if (!Auth::check()) {
- return 0;
- }
- return (FavouritePharmacy::where('user_id', Auth::user()->id)->where('pharmacy_id', $this->id)->count() == 1) ? 1 : 0;
- }
- }
- class Medicine extends Model
- {
- protected $appends = ['favourite'];
- public function orders()
- {
- return $this->belongsToMany(Order::class);
- }
- public function getFavouriteAttribute()
- {
- if (!Auth::check()) {
- return 0;
- }
- return (FavouriteMedicine::where('user_id', Auth::user()->id)->where('medicine_id', $this->id)->count() == 1) ? 1 : 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement