crz
crz

Reputation: 458

Laravel caching view errors Serialization of 'Closure' is not allowed

I am making a beautiful web app and got an error when trying to cache a view using command:

$view = View::make('templates.view1', array(
                'a' => $a,
                'b' => $b
        ));

Cache::put($key, $view, 30);

It throws

Serialization of 'Closure' is not allowed

to my face. I've tried with remember method but not succeed.

Cache::remember($key, 30, function($a, $b){
            return View::make('templates.view1', array(
                'a' => $a,
                'b' => $b
            ));
        });

How can I solve this issue?

Upvotes: 1

Views: 2346

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

You need to use render() method:

$view = View::make('templates.view1', array(
                'a' => $a,
                'b' => $b
        ))->render();

to convert this view to string. Otherwise you use Illuminate\View\View object

Upvotes: 6

Related Questions