tonyxhepa / laravel-restaurant-reservation

72 stars 67 forks source link

Attempt to read property "menus" on null #3

Open KhasanLaudry opened 2 years ago

KhasanLaudry commented 2 years ago

after clonning the repo and setting everything up, I run php artisan serve, I encounter error Attempt to read property "menus" on null on homapage welcome.blade.php line 124

Screenshot 2022-08-04 at 13 32 53
kashyap-hindocha commented 2 years ago

Same here.

rukundo-joe commented 1 year ago

How did you resolve it please? I've encountered the same error here!

rukundo-joe commented 1 year ago

Sir @laraveller kindly help us!

Marciellepaula commented 1 year ago

same

abdullafahem commented 1 year ago

It is simple just before the foreach you will add this line @if(!is_null($specials)) The final code is:

@if(!is_null($specials))
 @foreach ($specials->menus as $menu)
                    <div class="max-w-xs mx-4 mb-2 rounded-lg shadow-lg">
                        <img class="w-full h-48" src="{{ Storage::url($menu->image) }}" alt="Image" />
                        <div class="px-6 py-4">
                            <h4 class="mb-3 text-xl font-semibold tracking-tight text-green-600 uppercase">
                                {{ $menu->name }}</h4>
                            <p class="leading-normal text-gray-700">{{ $menu->description }}.</p>
                        </div>
                        <div class="flex items-center justify-between p-4">
                            <span class="text-xl text-green-600">${{ $menu->price }}</span>
                        </div>
                    </div>
                @endforeach
@else
<div>No item was found</div>
@endif

Thank you guys!

Samimi-Information-Technology commented 6 months ago

Fix for ---> "menus" on null'.

You need a category named Specials.

Use below sql statement:

INSERT INTOcategories(name,description,image,created_at,updated_at) VALUES ('Salads', 'Best Salads', 'public/categories/g9KVcF1CNYHhz10DepRga3Qln6Cuen8NsTL0YLRT.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), ('Specials', 'Today\'s Specials Menu', 'public/categories/JtbQlbhxQZfPIofqpc4X1KEQ3D6UxqCaALzxYgXd.png', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

Note: Change the images with your own uploaded or keep it blank and use the below instead.

INSERT INTOcategories(name,description,created_at,updated_at) VALUES ('Salads', 'Best Salads', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), ('Specials', 'Today\'s Specials Menu', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

Hope this helps.