Skip to content

Instantly share code, notes, and snippets.

@dura0ok
Created March 20, 2019 07:32
Show Gist options
  • Save dura0ok/cc92ad4f7e23ff17ff824576f7d64b9d to your computer and use it in GitHub Desktop.
Save dura0ok/cc92ad4f7e23ff17ff824576f7d64b9d to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class Shoplocation extends Model
{
protected $guarded = [];
protected $hidden = ['created_at', 'updated_at', 'shop_id'];
public function shop()
{
return $this->hasManyThrough(Shop::class, Category::class, 'shop_id', 'category_id', 'id', 'id ');
}
public function scopeByCity($query)
{
return $query->whereHas('shop', function ($query) {
return $query->where('city_id', request()->hasCookie('loc') ? request()->cookie('loc') : 1);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment