12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Models;
- use App\Http\Requests\IndexHelper;
- use App\Models\Enums\DisplayIndexObjectType;
- use EloquentFilter\Filterable;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Auth;
- class NamingRule extends Model
- {
- use HasFactory, Filterable;
- public $timestamps = true;
- protected $guarded = [
- 'id'
- ];
- protected $casts = [
- 'combination_rules' => 'array'
- ];
- protected static function booted()
- {
- parent::booted(); // TODO: Change the autogenerated stub
- static::creating(function (NamingRule $namingRule){
- $type =DisplayIndexObjectType::NAMERULE;
- $displayIndex = IndexHelper::getObjectMaxIndex($type,$namingRule->company_id);
- $namingRule->display_id =$displayIndex;
- });
- }
- public function scopeAllowed(Builder $query)
- {
- if (!Auth::user()->super_admin) {
- $query->where("company_id", Auth::user()->company_id);
- }
- }
- public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
- {
- return $this->belongsTo(Company::class);
- }
- }
|