Laravel 5.1 ERROR: FatalErrorException in Model.php line 852: Class 'App \ Vendor' not found

1

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 ??

    
asked by anonymous 14.01.2016 / 20:15

1 answer

0

@Junior Morais

Make sure the Models are in the root of the "app" folder then just put

namespace App;

In the Models and Service Models before the line:

use Illuminate\Database\Eloquent\Model;

Detail: If your models are in a folder other than the app, this will have to be set in the namespace quoted above.

I hope it helps.

    
13.02.2016 / 21:30