I have variable sets all my views in AppServiceProvider when I use that variable in the controller it says:
Undefined variable
Code
AppServiceProvider.php
View::composer('*', function ($view) {
$ProductSettings = ProductSetting::all();
foreach($ProductSettings as $psetting){
$show_unavailable = $psetting->show_unavailable;
$show_quantities = $psetting->show_quantities;
$product_pagination = $psetting->pagination;
$max_short_desc = $psetting->max_short_desc;
$allow_delivery_time = $psetting->allow_delivery_time;
$addtocart_on_attribute = $psetting->addtocart_on_attribute;
$outofstock_lable = $psetting->outofstock_lable;
$product_orderby = $psetting->orderby;
}
$view->with('show_unavailable', $show_unavailable);
$view->with('show_quantities', $show_quantities);
$view->with('product_pagination', $product_pagination);
$view->with('max_short_desc', $max_short_desc);
$view->with('allow_delivery_time', $allow_delivery_time);
$view->with('addtocart_on_attribute', $addtocart_on_attribute);
$view->with('outofstock_lable', $outofstock_lable);
$view->with('product_orderby', $product_orderby);
});
Controller
//codes...
$products = Product::whereHas('categories', function ($query) use ($slug) {
$query->where('slug', $slug);
})->paginate($product_pagination);
//codes...
Based on my database values product_pagination is set to 12 which means my code is like: ->paginate(12);
Question
Any idea why I get undefined error?
Update
table

$view->withdoesn't give the controller the variable?