(63) Local Scope in Laravel | Query Scope in Laravel | Why we use Local Scope in Laravel
HTML-код
- Опубликовано: 10 сен 2024
- Local Scope in Laravel
Let say you do not like above approach and you do not prefer to apply global scope rather you want to apply local scope whenever necessary surely you can do that in Laravel.
Local scopes are prefixed using Scope keyword. In this case instead of defining global scope you can add local scope in your Laravel model like following:
public function scopeDelete($query)
{
return $query where('delete', 0);
}
How to apply local model scope in laravel?
Local scopes are easy to use in laravel you can use them as you need them. Let's take following example.
Dynamic Scopes in Laravel Model
Sometime you may want to pass additional parameter to your local scope. In that case we can pass dynamic parameter to our local scope and it will act as dynamic scope.
Local scope in laravel
Laravel step by step guide
Laravel full series
Laravel scratch to advance series
Laravel zero to hero course
Laravel guide
The project is stored in the given below directory.
github.com/Had...
If you are facing any problem during development, you can post your queries free of cost at solutions.cdlc... so our team will respond to you within 24 hours.
If you need paid help from us, please visit solutions.cdlc... to process a contract with us.
* Contact us: contact@cdlcell.com
* Our website: cdlcell.com
* My Twitter: / hadayatniazi3
* My FB: / hadayatniaziofficial
Follow us on LinkedIn: / cdlcell
Follow us on Tiktok: / cdlcell
Join us on Instagram: / cdlcell
Follow us on Facebook: / cdlcellpk
Join our Laravel Developers whatsapp group: chat.whatsapp....
#php
#phplaravel
#laravel
#webdevelopment
#cdl
#career_development_lab
#hadayatniazi
#coding
#technology