You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
637 B
26 lines
637 B
<?php
|
|
|
|
namespace App\Domains\System\Traits\Model;
|
|
|
|
use App\Domains\System\Models\File;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
|
|
|
/**
|
|
* @mixin Model
|
|
*/
|
|
trait HasFile
|
|
{
|
|
public function hasSingleFile(string $relation): MorphOne
|
|
{
|
|
return $this->morphOne(File::class, 'fileable')
|
|
->where('relation_name', $relation);
|
|
}
|
|
|
|
public function hasMultiFile(string $relation): MorphMany
|
|
{
|
|
return $this->morphMany(File::class, 'fileable')
|
|
->where('relation_name', $relation);
|
|
}
|
|
}
|
|
|