87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class Attender extends Model
|
||
|
|
{
|
||
|
|
use CrudTrait;
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| GLOBAL VARIABLES
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
|
||
|
|
protected $table = 'attenders';
|
||
|
|
// protected $primaryKey = 'id';
|
||
|
|
// public $timestamps = false;
|
||
|
|
protected $guarded = ['id'];
|
||
|
|
protected $fillable = [
|
||
|
|
'name',
|
||
|
|
'surname',
|
||
|
|
'email',
|
||
|
|
'file',
|
||
|
|
'is_attending',
|
||
|
|
'attended',
|
||
|
|
'consent_form'
|
||
|
|
];
|
||
|
|
// protected $hidden = [];
|
||
|
|
// protected $dates = [];
|
||
|
|
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| FUNCTIONS
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| RELATIONS
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
public function events(){
|
||
|
|
return $this->belongsToMany(Event::class, 'event_attenders', 'attender_id', 'event_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| SCOPES
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| ACCESSORS
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
|
||
|
|
/*
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
| MUTATORS
|
||
|
|
|--------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
public function setFileAttribute($value)
|
||
|
|
{
|
||
|
|
$attribute_name = "file";
|
||
|
|
$disk = "public";
|
||
|
|
$destination_path = "files/uploads";
|
||
|
|
|
||
|
|
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path, $fileName = null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function boot()
|
||
|
|
{
|
||
|
|
parent::boot();
|
||
|
|
static::deleting(function($obj) {
|
||
|
|
if($obj->file){
|
||
|
|
\Storage::disk('public')->delete($obj->file);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|