feat: add media
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Media extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'image_id',
|
||||
'category_id',
|
||||
'title',
|
||||
'caption',
|
||||
'type',
|
||||
'file_path',
|
||||
'external_url',
|
||||
'duration',
|
||||
'visibility',
|
||||
];
|
||||
|
||||
public function image()
|
||||
{
|
||||
return $this->belongsTo(Image::class);
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function notes()
|
||||
{
|
||||
return $this->morphMany(Note::class, 'noteable');
|
||||
}
|
||||
public function myNote()
|
||||
{
|
||||
return $this->morphOne(Note::class, 'noteable')->where('user_id', auth()->id());
|
||||
}
|
||||
|
||||
public function savedBy()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'saved_media')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function getUrlAttribute()
|
||||
{
|
||||
if ($this->file_path)
|
||||
return asset('storage/' . $this->file_path);
|
||||
|
||||
return $this->external_url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user