Namespaces and Laravel 5 with Eloquent Model-s

Recently I tried out the Laravel 5.  A lot has changed, overall it is using even more cutting edge technologies and best practices. On the other hand its learning curve is not so good anymore and this makes it harder for nwebie developers to start with it.

Major change is that you have to deal with namespaces on your own. Also the extends Eloquent is now replaced with extends Model (Illuminate\Database\Eloquent\Model) .  If your model name is Port then you need to import it in your controllers etc via “use App\Port;”

Example class looks now like:

 <?php namespace App;
 use Illuminate\Database\Eloquent\Model;
 class Port extends Model {

These are exceptions that might happen for you if you do not handle it properly:

Class ‘Illuminate\Database\Eloquent’ not found

FatalErrorException in Port.php line 5:Class ‘Eloquent’ not found

HandleExceptions->fatalExceptionFromError(array(‘type’ => ‘1’, ‘message’ => ‘Class ‘Illuminate\Database\Eloquent’ not found’

FatalErrorException in AdminController.php line 12: Class ‘App\Http\Controllers\Port’ not found

Leave a Reply

Your email address will not be published.