I would like to get many "badges" to one "company" I have 3 tables companies, badgy, badgy_company as pivot table. What should I try/do? Can someone give me a hint or something?
company.blade.php
@foreach($listings->badgy as $type)
<span class="label label-default">{!! $type->title !!}</span>
@endforeach
Badgy.php
class Badgy extends Model{
protected $table = 'badgy';
public function badgy()
{
return $this->hasMany(Company::class);
}
If I remove protected $table = 'badgy'; I get error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'MYDATABASE.badgies' doesn't exist
Company.php
public function badgy()
{
return $this->belongsToMany(Badgy::class);
}
In page controllers I try:
$listings = Company::find($id);
$listings = Company::query()->get();
If I need to provide any more info, please, just ask.
php artisan migrate, your table badgies not exist - J. Doe$listingsis meant to contain your companies, and you want for each companies to display its "badgy", so you miss the definition of theCompanyclass in your post. Please provide it and we can help you more. - Anwar