Good afternoon!
I'm trying to relate two tables: Services and Suppliers, follow the templates created:
Service Model
use Illuminate\Database\Eloquent\Model;
class Servico extends Model
{
protected $table = 'servicos';
protected $fillable = [
'nomeServico',
'id_fornecedor'
];
public function fornecedores(){
return $this->belongsTo("App\Fornecedor");
}
}
Supplier Model
use Illuminate\Database\Eloquent\Model;
class Fornecedor extends Model
{
protected $table = 'fornecedores';
protected $fillable = [
'id',
'nomeFornecedor'
];
public function servicos(){
return $this->hasMany('App\Servico');
}
}
In this way I am trying to execute the following procedure inside the ServicoController:
public function view($id){
$servico = Servico::find($id);
return view('servico.view',['servico'=>$servico]);
}
In the view I'm using the following code:
@extends('layout.principal')
@section('conteudo')
<h1>Id Serviço #{{$servico->id}}</h1>
Serviço: {{$servico->nomeServico}}<br/>
Fornecedor: {{$servico->fornecedores->nomeFornecedor}}<br/>
@stop
and I get the following error:
FatalErrorException in Model.php line 852: Class 'App\Fornecedor' not found
In this error screen the ID data and ServiceName are displayed correctly, however the above error appears in the vendor name display.
Can someone give me a light ??