【Laravel】artisanのmake:scopeコマンドを解説

Laravel

Laravel 10.xのartisanの「make:scope」コマンドを解説します。

Description

新しいグローバルスコープクラスの作成

Usage

php artisan make:scope [-f|--force] [--] <name>

Arguments

引数必須設営
name必須グローバルスコープクラス名

Options

オプション省略形必須説明
forcef-グローバルスコープが既に存在する場合でもクラスを作成

Examples

no options

php artisan make:scope FooScope
   INFO  Scope [app/Models/Scopes/FooScope.php] created successfully.  
<?php

namespace App\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class FooScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     */
    public function apply(Builder $builder, Model $model): void
    {
        //
    }
}

Follow me!

コメント

PAGE TOP
タイトルとURLをコピーしました