kithkin/app/Models/EventMeta.php

72 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EventMeta extends Model
{
protected $table = 'event_meta';
protected $primaryKey = 'event_id';
public $incrementing = false;
protected $fillable = [
'event_id',
'title',
'description',
'location',
'all_day',
'category',
'reminder_minutes',
'is_private',
'start_at',
'end_at',
'extra',
];
protected $casts = [
'all_day' => 'boolean',
'is_private' => 'boolean',
'start_at' => 'datetime',
'end_at' => 'datetime',
'extra' => 'array',
];
/**
* convenience wrapper that mimics an “UPSERT” for meta rows.
*
* @param int $eventId calendarobjects.id
* @param array $attrs keyed the same way youd pass to updateOrCreate
* @return static
*/
public static function upsertForEvent(int $eventId, array $attrs): self
{
$values = array_merge($attrs, ['event_id' => $eventId]);
return static::updateOrCreate(
['event_id' => $eventId], // lookup
$values // insert/update
);
}
/**
*
* relationships
*/
/* back-reference to Sabres calendarobjects row */
public function event(): BelongsTo
{
return $this->belongsTo(Event::class, 'event_id');
}
/* back-reference to location record */
public function location(): BelongsTo
{
return $this->belongsTo(Location::class, 'location_id');
}
}