0

I'm struggling to use models and classes in Laravel 5 'FatalErrorException' class "name" not found.

Take the User class as standard under the App/ folder, it will only work as $user = App\User::where... or I can go 'use App/User'... Rather than just User::where. How can I get around this back to L4 where it just worked?

Secondly I came to Session::get standard Laravel Class, same error class 'Session' not found.

Unable to find a solution after 4 hours I'm resorting to asking the question... Thanks.

4
  • 1
    use namespaces, put use Session, use app/models/User Commented Mar 22, 2015 at 8:08
  • namespace doesn't forces that directory. you put that file into such folder that's why it maps the path such. Commented Mar 22, 2015 at 8:14
  • Thank you, saved me from more stress and grey hairs! Commented Mar 22, 2015 at 8:17
  • Further to this I have created a model file called Site.php which holds several classes i.e. class Testimonials extends Model {}. In a controller where I have use App/Site it won't load my Testimonial::getRandom function... says class not found!? Commented Mar 26, 2015 at 5:58

2 Answers 2

1
use App\Site;

Site::all();

or

\App\Site::all();
Sign up to request clarification or add additional context in comments.

1 Comment

I actually want to comment on this comment but I dont have enough reputation. Sorry - stackoverflow.com/questions/29192215/…
1

for laravel 5 you need to use namaspace if you want to use session you need to use that line in top of the class

use Session;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.