🚗🏍️ Welcome to Motoshare!

Turning Idle Vehicles into Shared Rides & New Earnings.
Why let your bike or car sit idle when it can earn for you and move someone else forward?

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Partners earn. Renters ride. Everyone wins.

Start Your Journey with Motoshare

Laravel Cookies: Best Practices & Implementation Guide

Laravel

In Laravel, cookies are used to store data on the client-side browser. Laravel provides a convenient way to manage cookies using the Illuminate\Cookie package.

Here’s an overview of working with cookies in Laravel:

Setting a Cookie: You can set a cookie using the cookie helper function or the Response instance. For example:

// Using the cookie helper
cookie('name', 'value', $minutes);

// Using the Response instance
$response = new Response('Hello');
$response->cookie('name', 'value', $minutes);

The cookie helper function accepts three arguments: name, value, and expiration time in minutes. Illuminate\Session

Getting a Cookie Value: You can retrieve the value of a cookie using the cookie helper function or the Request instance. For example:

// Using the cookie helper
$value = cookie(‘name’);

// Using the Request instance
$value = $request->cookie(‘name’);

Attaching Cookies to Responses:
When sending a response, you can attach cookies using the withCookie method on the Response instance. For example:

return response('Hello')->withCookie(cookie('name', 'value', $minutes));

Forgetting a Cookie:
To remove a cookie, you can use the forget method on the Response instance. For example:

return response('Hello')->withCookie(cookie()->forget('name'));

This will set the cookie with an expiration date in the past, effectively deleting it from the client-side browser.

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
1
0
Would love your thoughts, please comment.x
()
x