Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel global scope

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

laravel local scope

<?php
 
namespace AppModels;
 
use IlluminateDatabaseEloquentModel;
 
class User extends Model
{
    /**
     * Scope a query to only include popular users.
     *
     * @param  IlluminateDatabaseEloquentBuilder  $query
     * @return IlluminateDatabaseEloquentBuilder
     */
    public function scopePopular($query)
    {
        return $query->where('votes', '>', 100);
    }
 
    /**
     * Scope a query to only include active users.
     *
     * @param  IlluminateDatabaseEloquentBuilder  $query
     * @return void
     */
    public function scopeActive($query)
    {
        $query->where('active', 1);
    }
}
Comment

laravel global scope

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

PREVIOUS NEXT
Code Example
Php :: laravel file store 
Php :: parsing html in php 
Php :: php input time validation 
Php :: switch php versions 
Php :: laravel force login by id 
Php :: how to make model and controller in laravel 
Php :: php lowercase function 
Php :: radio button select in php 
Php :: route codeigniter 
Php :: add brackets to string php 
Php :: laravel valet refresh env 
Php :: Laravel Adding Cookie Consent 
Php :: sendmail php 
Php :: Notice: Array to string conversion php 
Php :: create laravel 8 resource route 
Php :: laravel collection forget 
Php :: laravel faker select between options 
Php :: eloquent batch insert 
Php :: symfony messenger route 
Php :: send mail using php mail function on localhost using xampp server 
Php :: how run job laravel in cpanel host 
Php :: debian install php 
Php :: php function 
Php :: PHP | Send Attachment With Email 
Php :: get php ini config from terminal 
Php :: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted 
Php :: laravel tinker insert db record 
Php :: how to download file from s3 bucket using php 
Php :: mac install php-fpm 
Php :: how to save multiple records in database using laravel 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =