PHP code example of beyondcode / laravel-scope-checks
1. Go to this page and download the library: Download beyondcode/laravel-scope-checks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
beyondcode / laravel-scope-checks example snippets
class User extends Model
{
use HasScopeChecks;
public function scopeActive($query)
{
$query->where('active', true);
}
public function scopeActive($query)
{
return $query->where('active', 1);
}
}
// Now you can call your scope check using:
$user->isActive();
use \BeyondCode\LaravelScopeChecks\HasScopeChecks;
class Post {
use HasScopeChecks;
public function scopePublished($query)
{
return $query->where('active', 1);
}
public function scopeMinimumRating($query, $rating = 5)
{
return $query->where('rating', '>=', $rating);
}
}