Changeset View
Changeset View
Standalone View
Standalone View
src/app/Fs/Item.php
Show All 18 Lines | |||||
*/ | */ | ||||
class Item extends Model | class Item extends Model | ||||
{ | { | ||||
use BelongsToUserTrait; | use BelongsToUserTrait; | ||||
use SoftDeletes; | use SoftDeletes; | ||||
use UuidStrKeyTrait; | use UuidStrKeyTrait; | ||||
public const TYPE_FILE = 1; | public const TYPE_FILE = 1; | ||||
public const TYPE_FOLDER = 2; | public const TYPE_COLLECTION = 2; | ||||
public const TYPE_INCOMPLETE = 4; | public const TYPE_INCOMPLETE = 4; | ||||
/** @var array<int, string> The attributes that are mass assignable */ | /** @var array<int, string> The attributes that are mass assignable */ | ||||
protected $fillable = ['user_id', 'type']; | protected $fillable = ['user_id', 'type']; | ||||
/** @var array<string, string> The attributes that should be cast */ | /** @var array<string, string> The attributes that should be cast */ | ||||
protected $casts = [ | protected $casts = [ | ||||
'created_at' => 'datetime:Y-m-d H:i:s', | 'created_at' => 'datetime:Y-m-d H:i:s', | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | private function storeProperty(string $key, $value): void | ||||
} | } | ||||
} else { | } else { | ||||
$this->properties()->updateOrCreate( | $this->properties()->updateOrCreate( | ||||
['key' => $key], | ['key' => $key], | ||||
['value' => $value] | ['value' => $value] | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* All relations for this item | |||||
machniak: s/user/item/ | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |||||
*/ | |||||
public function relations() | |||||
{ | |||||
return $this->hasMany(Relation::class); | |||||
} | |||||
/** | |||||
* Child relations for this item | |||||
Done Inline ActionsThe descriptions of these three methods should probably explain the difference between them in some way. machniak: The descriptions of these three methods should probably explain the difference between them in… | |||||
* | |||||
* Used to retrieve all items in a collection. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | |||||
*/ | |||||
public function children() | |||||
{ | |||||
return $this->belongsToMany(Item::class, 'fs_relations', 'item_id', 'related_id'); | |||||
} | |||||
/** | |||||
* Parent relations for this item | |||||
* | |||||
* Used to retrieve all collections of an item. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | |||||
*/ | |||||
public function parents() | |||||
{ | |||||
return $this->belongsToMany(Item::class, 'fs_relations', 'related_id', 'item_id'); | |||||
} | |||||
} | } |
s/user/item/