Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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);
    }
}
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #local #scope
ADD COMMENT
Topic
Name
9+6 =