Preview: Slot.php
Size: 2.21 KB
/var/www/multi-event-cfp.bitkit.dk/httpdocs/app/Models/Slot.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property mixed $event_id
* @property mixed $id
*/
class Slot extends Model
{
use HasFactory;
protected $fillable = [
'event_id',
'presentation_id',
'abstract_id',
'session_id',
'start_date',
'end_date',
'duration',
'title',
'type',
'order',
'reserved',
'exclude_from_website',
'break_slot',
'featured_by',
'sponsored_by'
];
protected $casts = [
'start_date' => 'date:Y-m-d H:i:s',
'end_date' => 'date:Y-m-d H:i:s',
'created_at' => 'date:Y-m-d H:i:s',
'updated_at' => 'date:Y-m-d H:i:s',
'slot_users' => AsArrayObject::class,
'abstract_presentation_track' => AsArrayObject::class,
'break_slot' => 'boolean',
'featured_by' => 'boolean',
'sponsored_by' => 'boolean'
];
//===========================================//
//relations
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function presentation(): BelongsTo
{
return $this->belongsTo(Presentation::class);
}
public function abstract(): BelongsTo
{
return $this->belongsTo(Abstracts::class, 'abstract_id');
}
public function session(): BelongsTo
{
return $this->belongsTo(Session::class);
}
public function users($role = null): BelongsToMany
{
$query = $this->belongsToMany(User::class, 'slot_users')
->using(SlotUser::class)
->withPivot(['id', 'role', 'is_moderator', 'order'])
->withTimestamps()
->orderBy('slot_users.order', 'asc');
if ($role)
$query->where('slot_users.role', '=', $role);
return $query;
}
public function slotUser(): BelongsTo
{
return $this->belongsTo(SlotUser::class);
}
}
Directory Contents
Dirs: 0 × Files: 26