L
L
Living4tomorrow2020-02-07 21:21:43
Laravel
Living4tomorrow, 2020-02-07 21:21:43

Is there a method in Laravel collection that checks if it is empty?

It is necessary to make such logic that the user can send a request once a day, this works if the user already has requests, and if there are no requests, then the error

is the code, I don’t understand how to check that there is nothing in the collection.

@if(auth()->user()->manager)

<a href="requests/view">Show reuqests</a>

@else

    @if(auth()->user()->requests()->latest()->first()->created_at->timestamp - now()->timestamp > 86400)
        <a href="/requests/create">You can Send a request</a>
    @else
    <p>You already sent a request today, comeback tomorrow</p>
    @endif
@endif


mistake
Trying to get property 'created_at' of non-object (View: C:\xampp\htdocs\Callback\resources\views\userWelcome.blade.php)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-02-07
@Living4tomorrow

https://laravel.com/docs/master/collections#method...
https://laravel.com/docs/master/collections#method...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question