Changeset View
Changeset View
Standalone View
Standalone View
src/app/Fs/Item.php
<?php | <?php | ||||
namespace App\Fs; | namespace App\Fs; | ||||
use App\User; | use App\User; | ||||
use App\Traits\BelongsToUserTrait; | |||||
use App\Traits\UuidStrKeyTrait; | use App\Traits\UuidStrKeyTrait; | ||||
use Illuminate\Database\Eloquent\Casts\Attribute; | use Illuminate\Database\Eloquent\Casts\Attribute; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
/** | /** | ||||
* The eloquent definition of a filesystem item. | * The eloquent definition of a filesystem item. | ||||
* | * | ||||
* @property string $id Item identifier | * @property string $id Item identifier | ||||
* @property int $type Item type | * @property int $type Item type | ||||
* @property string $path Item path (readonly) | * @property string $path Item path (readonly) | ||||
* @property int $user_id Item owner | * @property int $user_id Item owner | ||||
*/ | */ | ||||
class Item extends Model | class Item extends Model | ||||
{ | { | ||||
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_FOLDER = 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 */ | ||||
▲ Show 20 Lines • Show All 131 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] | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* The user to which this item belongs. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function user() | |||||
{ | |||||
return $this->belongsTo(User::class, 'user_id', 'id'); | |||||
} | |||||
} | } |