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