add attachments structure

This commit is contained in:
2023-02-24 12:53:26 +10:00
parent 4ee8fd2400
commit 6ebb915c68
6 changed files with 170 additions and 1 deletions

28
app/Models/Attachment.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Attachment extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'media_id',
];
/**
* Get attachments attachable
*/
public function attachable()
{
return $this->morphTo();
}}

View File

@@ -29,4 +29,12 @@ class Event extends Model
'hero',
'content'
];
/**
* Get all of the post's attachments.
*/
public function attachments()
{
return $this->morphMany('App\Attachment', 'attachable');
}
}

View File

@@ -27,7 +27,7 @@ class Post extends Model
/**
* Get the file user
* Get the post user
*
* @return BelongsTo
*/
@@ -35,4 +35,12 @@ class Post extends Model
{
return $this->belongsTo(User::class);
}
/**
* Get all of the post's attachments.
*/
public function attachments()
{
return $this->morphMany('App\Attachment', 'attachable');
}
}