Summer Sale! All accounts are 50% off this week.

Sahand-feizi's avatar

Sahand-feizi wrote a reply+100 XP

2h ago

Cookies are missing from request when feature testing in Laravel

this is a common error in testing cookies, and I had this problem before. Something that works for me was changing the this:

$this->withCookie($cookie->getName(), $cookie->getValue())
        ->putJson(route('auth.refresh-tokens'));

to this:

$response = $this->call(
        'PUT',
        '/api/auth/refresh-tokens',
        [],
        [$cookie->getName() => $cookie->getValue()]
);

withCookie() relies on Laravel's testing cookie jar, while call() passes cookies directly to the request. In this case, using call() bypassed the helper layer and ensured the refresh_token cookie was attached to the PUT request correctly.

I hope this helps.

Sahand-feizi's avatar

Sahand-feizi wrote a comment+100 XP

1mo ago

Laravel From Scratch (2026 Edition): Ep 28, Idea Cards

@LaramanCode I did the exact same, and I think this solution looks much cleaner.

Sahand-feizi's avatar

Sahand-feizi liked a comment+100 XP

1mo ago

Laravel From Scratch (2026 Edition): Ep 28, Idea Cards

Another version

File app/IdeaStatus.php

File resources/views/components/ide/status-label.blade.php \

<span @class(["inline-block text-xs rounded-full border mt-2 px-2 p-y-1 text-sx font-medium",
    $status->colors(),
])>
            {{  $status->label() }}
</span>

//File resources/views/components/card.blade.php \
<a href="{{route('ideas.show', $idea->id)}}" {{ $attributes(['class'=>'border border-border rounded-lg bg-card p-4 md:text-sm'])}} >
    <h3 class="text-foreground text-lg">{{$idea->title}}</h3>

    <x-idea.status-label :status="$idea->status" />

    <div class="mt-5 line-clamp-3">{{ $idea->description }}</div>
    <div class="mt-4">{{ $idea->created_at->diffForHumans() }}</div>
</a>

File resources/views/idea/index.blade.php

<x-layout>
    <div class="text-muted-foreground">
        <header class="py-8 md:py-12">
            <h1 class="text-3xl font-bold">Ideas</h1>
            <p class="text-muted-foreground text-sm mt-2"> Capture yor thoughts. Make a plan.</p>
        </header>
        <div class="mt-10">
            <div class="grid md:grid-cols-2 gap-6">
                @forelse($ideas as $idea)
                    <x-card :idea="$idea"/>
                @empty
                    <h2 class="text-4xl font-bold text-purple-600 ">No ideas at this time</h2>
                @endforelse
            </div>
        </div>
    </div>
</x-layout>

Sahand-feizi's avatar

Sahand-feizi wrote a comment+100 XP

1mo ago