13
votes

I am trying to create a cookie in laravel 5 with

$cookie = Cookie::make('name', 'value');

in controller and i want to attach to the view. But it shows the error

Class 'App\Http\Controllers\Cookie' not found.

How to solve this problem ?

3
use Cookie;. Done.Amelia

3 Answers

15
votes

Most Class not found are usually caused my incorrect namespace:

try

$cookie = \Cookie::make('name', 'value');

or add use Cookie; in your class like so:

<?php namespace App\Http\Controllers;

use Cookie;

UserController extends Controller{

}
0
votes

Put a slash before the Cookie it will work . Like this

$cookie = \Cookie::make('name', 'value');
0
votes
cookie('cookiename','your value',time);