vendredi 3 août 2018

SQLSTATE[42S22]: Column not found: 1054 Laravel

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire