11

When I use cache on laravel, 5 it keeps on giving me an error Class 'App\Http\Controllers\Cache' not found

<?php namespace App\Http\Controllers;

class ChannelController extends Controller {

    public function popular()
    {
        Cache::put('test','test value',10);
    }
}

It's just a simple cache but still not working. By the way, my config for cache is set to memcached - and it is working fine on laravel 4.2, but not on laravel 5.

2 Answers 2

15

Cache is not inside your App namespace, you can either:

<?php namespace App\Http\Controllers;

use \Cache;
class ChannelController extends Controller {

You can then use Cache throughout your class. Alternatively you can add a \ to the existing line you have:

\Cache::put('test','test value',10); 
Sign up to request clarification or add additional context in comments.

Comments

7

You just need to import Cache. Add this to the top of your file after the namespace declaration but before your class.

use Cache;

1 Comment

It works, thanks :) sorry i have to put the check on the first respond, anyway thanks for the help!

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.