laravel為模型中所有查詢統一添加WHERE條件


第一種方法

<?php
namespace Table;
use Illuminate\Database\Eloquent\Builder;
/**
*
*
*/
class TSingleService extends Table{
     
    protected $table = 'single_service_list';
    public $timestamps = false;

    /**
     * 設置單項服務全局查詢條件
    */
    protected static function boot()
     {
         parent::boot(); // TODO: Change the autogenerated stub
         static::addGlobalScope('avaiable',function (Builder $builder){
             $builder->where('deleted_at','=',NULL);
         });
     }
}

  

第二種方法

<?php
namespace Table;

use Illuminate\Database\Eloquent\SoftDeletes;
/**
*
*
*/
class TSingleService extends Table{
    use SoftDeletes;
    protected $table = 'single_service_list';
    protected $dates = ['deleted_at'];
    public $timestamps = false;

}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM