I’m having trouble placing a variable in my controller

I created an ecommerce store using Laravel, where I added all the controllers and the routes which seem to be working well without any errors. But recently I’ve been trying to add other ‘related products’ to my website. But when I ran the website after adding it, I get the error

‘Undefined variable:categories’.

I’ve already placed the routed in my controller and allocated it the variable product. The only thing I don’t know is how I would add another variable to the controller. I’ve tried nearly everything but nothing seems to work up to now. Here’s my code.

<!--Related Products-->
<div class="col-md-4">
<ul class="list-group list-group-horizontal-md">
<li class="list-group-item active">
Related Products
<li>
@foreach($categories as $category)
<a href="" class="list-group list-group-horizontal-md list-group-item-action">

()
</a>
@endforeach
</ul>
</div>
<!--Related Products-->

Controller

public function show(Product $product)
{
//
return view('products.show')->withProduct($product);
}

Routes

Route::get('/ourbooks', [AppHttpControllersOurbooksController::class, 'ourbooks'])->name('ourbooks');
Route::get('/category/products/{category}', '[email protected]')->name('category.products');
Route::resource('/products','AppHttpControllersProductController');
Route::resource('/orders','AppHttpControllersOrderController');

Can any help me and show me how to get rid of the error?

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/3mt5Jyv
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.