I'm having a tough time migrating the Laravel 4.2
files to Laravel 5.1
. I know it works with a lot of namespacing
. So probably most of my errors would be because of the namespace
issues. But I'm a bit new to namespace
things. So I've some problems. I hope this would also benefit to some other users as well.
Composer.json
file :
"classmap": [
"database",
"app/Http/Controllers",
"app/Models"
],
App\Models
structure for the Models
.I'm getting this error related to Models
. Where Backers.php
and User
are the models
. What namespace
should I provide to avoid this?
FatalErrorException in Backers.php line 16: Class 'User' not found
I've used User::find($id)
in some Views
and Controllers
. Instead of always calling \App\User::find($id)
, is there any other way I could approach this problem?
displayLesson
is a route
name and sometimes I'm getting an error like
App\Http\Controllers\displayLesson not found.
How can I approach these problems?
I don't understand ur exact problem but u can write "use .. as ..." at the top of the class after namespace the class name you use alot to avoid writing App\User
namespace App\http\superImportantController Use App\User as User;
Or not a very good practice but time consuming is to add your model into facades in app.php
However , I guess the best practice is to use proper namespacing to be compliant with psr-7