== How to fix it in Laravel

=== Code examples

include::../../common/fix/code-rationale.adoc[]

==== Noncompliant code example

[source,php,diff-id=11,diff-type=noncompliant]
----
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cookie;

Route::get("/checkcookie", function (Request $request) {
    if (!$request->hasCookie('PHPSESSID')) {
        $value = $request->query->get('cookie');
        Cookie::queue('PHPSESSID', $value, 86400); // Noncompliant
    }

    return view('welcome');
});
----

==== Compliant solution

[source,php,diff-id=11,diff-type=compliant]
----
use Illuminate\Http\Request;

Route::get("/checkcookie", function (Request $request) {
    if (!$request->hasCookie('PHPSESSID')) {
        return redirect()->route('getcookie');
    }

    return view('welcome');
});
----

include::../../common/fix/how-does-this-work.adoc[]
