Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel scope relationship

class User extends Model {

    public function scopePopular($query)
    {
        return $query->where('votes', '>', 100);
    }

    public function scopeWomen($query)
    {
        return $query->whereGender('W');
    }

}
Comment

laravel scope function model

public function scopeOwner($query, $id)
{
    return $query->where('user_id', $id);
}

public static function getTicket($id)
{
    $ticket = Support::where('id', $id)->owner(Auth::user()->id)->first();

    return $ticket;
}

You can also do this

public static function getTicket($id)
{
    $ticket = static::where('id', $id)->owner(auth()->id())->first();

    return $ticket;
}
Comment

laravel global scope

protected static function booted()
    {
        self::addGlobalScope('latest', function ($query){
            $query->latest('updated_at');
        });
    }
Comment

scope sample laravel 8

// in your model
public function scopeField($query)
    {
        return $query->where('field', 'value'); //  if in header return $query->where('field', request()->field);
    }

// in your controller or repository 
    public function index()
    {
        return Package::field()->get();
    }
Comment

laravel scope relationship

class User extends Model {

    protected function getDateFormat()
    {
        return 'U';
    }

}
Comment

laravel scope relationship

$users = User::popular()->women()->orderBy('created_at')->get();
Comment

laravel scope

public function apply(Builder $builder, Model $model)
    {
        $builder->where('age', '>', 200);
    }
Comment

laravel global scope

protected static function boot()
    {
        parent::boot();
  
        static::addGlobalScope(new ArchiveScope);
    }
Comment

PREVIOUS NEXT
Code Example
Php :: public $baseURL codeigniter 4 
Php :: laravel package development 
Php :: create laravel update 
Php :: require password confirm laravel 
Php :: cakephp 
Php :: laravel flash message 
Php :: self vs this in php 
Php :: laravel field types from database field type 
Php :: phpunit run one test 
Php :: php backend generator 
Php :: php //input 
Php :: Laravel how to use @auth and @guest with multi authentication 
Php :: how to add drop a table in phpmyadmin 
Php :: check if is the last day of the month php 
Php :: laravel set middleware default 
Php :: php override built in functions 
Php :: php var_dump() 
Php :: php array form 
Php :: wherenotnull laravel 
Php :: magento 2 add cc transportbuilder 
Php :: myr currency symbol 
Php :: Problem getting updated value from child component to the parent component in a Laravel 9 with Vue 
Php :: how to remove index.php in codeigniter 3 route 
Php :: limit query laravel 
Php :: Primary Termmaatwebsite/excel store s3 
Php :: How to validate Envato Purchase Code in PHP 
Php :: No match for argument: phpmyadmin yum 
Php :: wp rest api remove _links 
Php :: Agregar clases de rol al body en WordPress 
Php :: php When I try to run my code in chrome, i see the code that I have made in phpstorm and not the function that it has to do 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =