Edvard Åkerberg Edvard Åkerberg - 4 months ago 26x
MySQL Question

Laravel 5 model class not found - hasMany

I am trying to get company employees using the has many method in model. But I get this error.

Fatal error: Class 'Employee' not found (View: /home/vagrant/Code/laravel/resources/views/frontpage.blade.php)

Here is my controller:

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Company;
use App\Employee;

public function index()
$data = Company::get();
$data = array(
'companies' => $data,

return view('frontpage', $data);

And here is my models: first one is Company.php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Employee;

class Company extends Model{

protected $table = 'company';

public function employee()
return $this->hasMany('Employee', 'company_id', 'id');

Here is the other model, Employee.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model{

public $table = "employee";


And here is the view



@foreach ($companies as $company)
<p>This is company {{ $company->name }}</p>
<p>{{ print_r($company->employee) }}</p>



Relation definitions require fully qualified class names to be passed.


return $this->hasMany('Employee', 'company_id', 'id');

with either

return $this->hasMany('App\Employee', 'company_id', 'id');


return $this->hasMany(Employee::class, 'company_id', 'id');