<?php
namespace App\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class DeleteScope implements Scope
{
protected $is_delete = 1; protected $delete_field = 'is_delete';
public function __construct(\App\Models\Model $model)
{
$this->is_delete = $model->getIsDelete();
$this->delete_field = $model->getDeleteField();
}
public function apply(Builder $builder, Model $model)
{
if ($this->is_delete == 0) $builder->where($this->delete_field, $this->is_delete);
}
}