1. To Set a cookie you can use the following code:
$ref = 'my cookie value'; return redirect('/')->withCookie('ref', $ref);
2. Then to get a cookie value you can do the following:
$cookie = $request->cookie('ref');
And it’s as easy as that. To learn more about laravel cookies you can visit the official documentation.
Additionally you can learn more about Laravel cookies by checking out this video by DevDojo: