How are AI tools helping solve real, complex, and time-consuming problems faster?

Nowadays, almost everyone is either using AI tools or thinking about incorporating them into their daily work. At the same time, many professionals are still hesitant, worrying that AI might replace their jobs. While those concerns are understandable, I believe the bigger risk is ignoring these tools altogether. From my experience, AI isn't replacing engineers—it is helping engineers work faster and focus on solving more meaningful problems. Like any other tool, its value depends on how effectively we use it. The more we learn to collaborate with AI, the more productive and efficient we can become. Here are two real examples from my recent work where AI tools helped me solve complex and time-consuming engineering problems significantly faster. AI helped me audit and upgrade my project's tech stack by checking dependency compatibility and flagging version-specific issues in advance. Instead of manually reviewing every package and verifying the latest compatible versions, I was ...

How to Show Cookie Policy Consent or GDPR Popup in Laravel using Cookie.

Cookie in Laravel

You can use the cookie in Laravel using the Helper method `cookie()` or method available with Request/Response Object or `Cookie` facade.

$request->cookie('name');

OR

use Illuminate\Support\Facades\Cookie;

Cookie::get('name');

To get more clarity on how to use the cookie in Laravel with an example to show cookie consent popup on your Laravel website and hide/remove it once you accept the policy.

Cookie Policy Consent Popup in Laravel

First, create and a Cookie Consent popup as notification to the footer section of your Laravel main blade template file. 

<div class="cookies-block">
        <h5>This website uses cookies</h5>
        <p>We use cookies to improve your experience and deliver personalised content. By using this website, you agree to our <a href="javascript:void()">Cookie Policy</a>.</p>
        <button class="okay-btn">ACCEPT</button>
 </div>

First, Now, Javascript snippet to capture click on the `ACCEPT` button, send ajax request to the server to create a cookie.

$(document).on('click','#footer .cookies-block button', function(e) {
    e.preventDefault();
    $.ajax({
        method: 'GET',
        url: '/cookie',
        data : {
            'name' : 'accept-cookie',
            'value' : true
        },
        success: function (response) {
            $('#footer').find('.cookies-block').hide();
        },
        error: function (error) {
            alert('Error: Please refresh the page');
        },
    });
});

Now you have to create a POST route with the public permission that maps to a method in the controller which returns the response with the cookie. 

//in route/web.php

Route::post('/cookie', 'PagesController@setCookie');

//in app/Http/Controllers/PagesController.php

public function setCookie(Request $request)
{
    return response('success')->cookie('accept-cookie', true, config('constants.COOKIE_ACCEPT_LIFETIME'));
}

Once Ajax request got success response, it creates a cookie, like as above with name `accept-cookie`.
you can check it in your browser's debug panel (press F12).
As now cookie stored in your browser now you make a check for the user who has already accepted the policy i.e. accept-cookie is stored or not. hence the consent popup can be wrap in check:

//in the main layout template
@if (!request()->cookie('accept-cookie')) //check if cookie not stored
    <div class="cookeies-block">
        <h5>This website uses cookies</h5>
        <p>We use cookies to improve your experience and deliver personalised content. By using this website, you agree to our <a href="javascript:void()">Cookie Policy</a>.</p>
        <button class="okay-btn">OK</button>
    </div>
@endif

Hope you got an idea. If still having any query or feedback for improvement, feel free to ask.

Comments

  1. If you need some more options you can use our Package for it. https://github.com/42coders/eu-cookie-consent

    ReplyDelete
    Replies
    1. most help full tutorial: https://devnote.in/how-to-add-gdpr-cookie-consent-in-laravel/

      Delete

Post a Comment

Popular posts from this blog

Differences between json and jsonb - JSON data type in PostgreSQL

Laravel Validation - Unique rule with multiple column and condition.

Using Virtual Columns in Laravel - Accessors and Appends