shenaldev's avatar

How to set cookie Inertia Render

Is it possible to set a cookie with inertia render. if yes how to do it

0 likes
1 reply
shahriar_shaon's avatar

Yes, you can set a cookie when returning an Inertia.js response. Inertia responses are still just normal HTTP responses from your backend framework, so you set cookies the same way you normally would. Inertia does not provide its own cookie API.

use Inertia\Inertia;
use Illuminate\Support\Facades\Cookie;

public function index()
{
    Cookie::queue('my_cookie', 'some value', 60); // 60 minutes

    return Inertia::render('Dashboard', [
        'example' => 'data',
    ]);
}

Please or to participate in this conversation.