James_B's avatar

Laravel 5.0 - 'Eloquent' not found

I must be doing something really silly..

<?php namespace Blog\Http\Repositories\Eloquent;

use Blog\Http\Repositories\TestRepositoryInterface;
use Eloquent;

class DbTestRepository extends Eloquent implements TestRepositoryInterface {

 public function names()
 {
    $names = ['Barry', 'Steve', 'Geoff', 'Mandy'];

    return $names[array_rand($names)];
 }

}
<?php namespace Blog\Http\Repositories;

interface TestRepositoryInterface
{
 public function names();
}
<?php namespace Blog\Http\Controllers;

use Illuminate\Routing\Controller;
use Blog\Http\Repositories\TestRepositoryInterface;

class HomeController extends Controller {

 public function index()
 {
    return view('hello');
 }

 public function test(TestRepositoryInterface $test)
 {
    var_dump($test->names());
 }

}

This would work in 4.3, but in 5.0 it doesn't for some reason.

0 likes
3 replies
Cocoon's avatar
Cocoon
Best Answer
Level 7

I think there is no Eloquent alias in Laravel 5.0. So you have to use the Model:

use Illuminate\Database\Eloquent\Model;

class DbTestRepository extends Model implements TestRepositoryInterface {

 ...
}

or create an alias in app.php

'Eloquent' => 'Illuminate\Database\Eloquent\Model',
acasar's avatar

Yes, Eloquent alias has been removed in Laravel 5 (as well as some other aliases used for extending, e.g. Controller), since it is not a very good practice to use aliases as your parent classes.

You can still add it back of course, but I would recommend referencing the full path instead.

James_B's avatar

I see, now things make sense.

Find it odd that the Eloquent alias was removed.

Thanks for the help.

Please or to participate in this conversation.