Spaces:
Running
Running
| namespace App\Models; | |
| use App\Services\ChapterServices; | |
| use App\Services\HashtagServices; | |
| use App\Services\TaggedServices; | |
| use Illuminate\Database\Eloquent\Factories\HasFactory; | |
| use Illuminate\Database\Eloquent\Model; | |
| use Illuminate\Support\Facades\Schema; | |
| use Spatie\Sluggable\HasSlug; | |
| use Spatie\Sluggable\SlugOptions; | |
| use App\Models\Traits\SearchableTraitExtend; | |
| class Benefit extends BaseModel | |
| { | |
| protected $table = "benefits"; | |
| protected $hidden = ['pivot']; | |
| protected $fillable =[ | |
| 'price', | |
| 'description', | |
| 'name', | |
| 'created_by', | |
| 'updated_by', | |
| 'created_at', | |
| 'updated_at', | |
| ]; | |
| const TIME = [ | |
| 'application_date', | |
| 'attendance_start_at', | |
| 'attendance_end_at', | |
| 'approved_at' | |
| ]; | |
| public static function boot() | |
| { | |
| parent::boot(); | |
| static::deleting(function ($model) { | |
| $packetBenefits = $model->packetBenefits; | |
| if($packetBenefits->isEmpty()){ | |
| $model->packetBenefits()->delete(); | |
| }else{ | |
| return false; | |
| } | |
| }); | |
| } | |
| // public function getSlugOptions() : SlugOptions | |
| // { | |
| // return SlugOptions::create() | |
| // ->generateSlugsFrom('comic_name') | |
| // ->saveSlugsTo('slug'); | |
| // } | |
| protected function columns(){ | |
| return Schema::getColumnListing('benefits'); | |
| } | |
| public function scopeExclude($query, $value = array()) | |
| { | |
| return $query->select( array_diff( $this->columns(), $value) ); | |
| } | |
| public function packets() | |
| { | |
| return $this->belongsToMany(Packet::class, 'packet_benefit', 'benefit_id','packet_id'); | |
| } | |
| public function packetBenefits() | |
| { | |
| return $this->hasMany(PacketBenefit::class, 'benefit_id'); | |
| } | |
| } | |