2 my application show the teacher**(profs)** and if i click on a prof it shows me the subjects that he teach (matiere). so i have Model Profs:
<?php
namespace App;
use App\Matiere;
use Illuminate\Database\Eloquent\Model;
class Prof extends Model
{
protected $fillable=array('nom','prenom','age','mail');
public function matieres(){
return $this->hasMany('Matiere');
}
}
Now when i click on a specifique teacher i call show methode :
public function show(Prof $prof)
{
return view('Prof.show',compact('prof'));
}
then in show.blade.php i try to show teacher s subjects
{!! $matiere=$prof->matieres !!}
<table class="table">
<thead><th>id</th><th>Nom matiere</th></thead>
@foreach ($matiere as $mat)
<tr>
<td>{{$mat->id}}</td><td>{{$mat->Nom}}</td>
</tr>
@endforeach
</table>
the Message error that i get is FatalErrorException in Model.php line 876: Class 'Matiere' not found
i try to fix the problem by adding use Matiere ; but it idn t work
how could i fix the problem ? thnks
i fix the problem by changing 2 Models
Prof :
<?php
namespace App;
use App\Matiere;
use Illuminate\Database\Eloquent\Model;
class Prof extends Model
{
protected $fillable=array('nom','prenom','age','mail');
public function matieres(){
return $this->hasMany(Matiere::class,'id_prof'); //Correction
}
}
And Matier :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Prof;
class Matiere extends Model
{
protected $fillable=array('Nom');
public function profs(){
return $this->BelongsTo(Prof::class,'id_prof'); //Correction
}
}