i have two tables
1.Categories [id(int),photo_id(int),name(string),created_ad(datetime),updated_at(datetime)]
2.Items [id(int),category_id(int),photo_id(int),name(string),description(text),created_ad(datetime),updated_at(datetime)]
my Category model
class Category extends Model
{
protected $fillable = ['name', 'photo_id'];
public function photo()
{
return $this->belongsTo('App\Photo');
}
}
my Items model
class Items extends Model
{
//
protected $fillable = [
'name', 'category_id', 'photo_id', 'description'
];
public function category()
{
return $this->belongsTo('App\Category');
}
public function photo()
{
return $this->belongsTo('App\Photo');
}
}
i just want to give items more then one id of category if its only one id i know how to display this
$item->category->name (give me the name of category from category table)
but, if i want more than one how can i do this ?
- i trying to take collumn category_id and make it to string type than take all ids in json , its work but than how i display this in view ?
2.i cant make in database column type json this is mariaDB.
ty for helper :)
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire