⏳۵۰٪ تخفیف فقط تا پایان جشنواره؛ بعدش همهچیز به قیمت قبل برمیگرده!
مشاهده دورههاسلام یک سوال دارم ممنون می شم راهنمایی کنید.
من داخل مدل خودم یک Global Scopes ساختم ولی در استفاده از اون داخل join() به مشکل خوردم و شروطی که داخل scope گذاشتم اعمال نمی شن . ممنون می شم بفرمایید مشکلم کجاست
اسکوپ
protected static function booted()
{
parent::booted();
static::addGlobalScope('rate.index', function (Builder $builder) {
$builder->where('rates.index', '=', 1);
});
}
protected static function booted()
{
parent::booted();
static::addGlobalScope('image.index', function (Builder $builder) {
$builder->where('product_images.index', '=', 1);
});
}
query :
$products = Product::join('rates', 'products.id', '=', 'rates.product_id')
->join('product_images', 'products.id', '=', 'product_images.product_id')
->select([
'products.id', 'products.name', 'products.slug',
'product_images.url', 'product_images.alt',
'rates.price', 'rates.discount', 'rates.discountExpirationDate'
])
->where([
['product_images.index', '=', 1],
['rates.index', '=', 1]
])
->whereIn('products.id', $extractSession['productIds'])
->get();
شروط where رو باید حتما بزارم وگرنه scope کار نمی کنه.
اولین نفری باشید که به این پرسش کمک میکند و مسیر حل مشکل را باز میکند.
اولین پاسخ را بنویسیدشاید پاسخ شما همینجا باشد