Pooja
Pooja

Reputation: 613

how to check if cookie exist in laravel 8

I am trying to check a condition based on cookie but I am not able to do that.

public function add_to_fav($product_id){

        $user_id = Cookie::has('u_id');
        if($user_id === 1){
            return "$is_already_added";
        } else{
            return "Login First";
        }


    }

Upvotes: 1

Views: 672

Answers (1)

Volodymyr Horiainov
Volodymyr Horiainov

Reputation: 36

I just use the isset($_COOKIE['u_id']) and it works. Hope it worked for you :)

Upvotes: 2

Related Questions