I'd add a media_categories table so it's more dynamic. Otherwise, if you add a new type with id of 5, you'd have to go in and add it into your code. Whereas if you had them in a different table, you could just do something like $media->category->type and get back "video" or "audio" or whatever else you may have.
Sep 5, 2018
3
Level 1
isVideo or isImage funcion on Multimedia model based on a belongsTo
Having this model for Multimedia files:
class Multimedia extends Model
{
protected $table = 'multimedias';
public $timestamps = false;
public function tipo_multimedia()
{
return $this->belongsTo('App\TipoMultimedia', 'tipo_multimedia_id');
}
}
Where tipos_multimedias (in english: multimedia types) table has records like this
id | nome
---------------------------------------
1 | Images of landscapes
2 | Videos of animals
3 | Videos of landscapes
4 | Images of vertebrate animals
Is it possible to add to Multimedia model function like isVideo and isImage based on what's the ID on tipos_multimedia table?
Or would be simpler to add a tinyint(1) field called isImage on tipo_multimedias tables so I'd know if it was 0 it would be an image and 1 for videos? But for this the first question is still valid.
Thanks in advace!
Level 67
1 like
Please or to participate in this conversation.