Changeset View
Changeset View
Standalone View
Standalone View
src/app/Share.php
- This file was added.
<?php | |||||
namespace App; | |||||
use App\Traits\UuidStrKeyTrait; | |||||
use Illuminate\Database\Eloquent\Model; | |||||
/** | |||||
* The eloquent definition of a Share. | |||||
* | |||||
* @property string $id Share identifier | |||||
* @property int $rights Access rights | |||||
* @property int $shareable_id The shared object identifier | |||||
* @property string $shareable_type The shared object type (class name) | |||||
* @property string $user Permitted user (email) | |||||
*/ | |||||
class Share extends Model | |||||
{ | |||||
use UuidStrKeyTrait; | |||||
public const READ = 1; | |||||
public const WRITE = 2; | |||||
public const ADMIN = 4; | |||||
/** @var array<int, string> The attributes that are mass assignable */ | |||||
protected $fillable = [ | |||||
'shareable_id', | |||||
'shareable_type', | |||||
'rights', | |||||
'user', | |||||
]; | |||||
/** @var array<string, string> The attributes that should be cast */ | |||||
protected $casts = [ | |||||
'rights' => 'integer', | |||||
]; | |||||
/** | |||||
* Principally shareable object such as Room. | |||||
* Note that it may be trashed (soft-deleted). | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function shareable() | |||||
{ | |||||
return $this->morphTo()->withTrashed(); // @phpstan-ignore-line | |||||
} | |||||
/** | |||||
* Rights mutator. Make sure rights is integer. | |||||
*/ | |||||
public function setRightsAttribute($rights): void | |||||
{ | |||||
$this->attributes['rights'] = $rights; | |||||
} | |||||
} |