Answer the question
In order to leave comments, you need to log in
Widget problem. What is the best way to organize widgets in Laravel 5.2?
The site has a system of widgets, which I found on the English Internet.
In the app folder, I created the "Widgets" folder, the structure looks like this:
At the root of the "Widgets" folder, I created the ServiceProvider.php file with the following content:
namespace App\Widgets;
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
$widgets = config("widget.widgets");
while (list(,$widget) = each($widgets)) {
if(is_dir(__DIR__.'/'.$widget.'/Views')) {
$this->loadViewsFrom(__DIR__.'/'.$widget.'/Views', 'widget.' . $widget);
}
}
}
public function register(){
}
}
return [
'widgets' => [
'menu',
'slider',
'carousel',
'reviews',
'cart',
'wishlist',
'viewed',
'articles',
],
];
namespace App\Widgets\Slider;
class Slider
{
public function show()
{
$items = \App\Models\Slider::whereIsPublished(1)->get();
return view('widget.slider::index', compact('items'));
}
}
$slider = new Slider();
and in the right place $slider->show();
ErrorException in FileViewFinder.php line 112: No hint path defined for [widget.slider]. (View: /home/wearsh00/wear-shop.pp.ua/project/resources/views/index.blade.php)
Answer the question
In order to leave comments, you need to log in
The problem is a case mismatch. On windows it is ignored, but not on shared hosting.
Solved by fixing the case in Widgets/ServiceProvider.php like this:
if(is_dir(__DIR__. '/' . ucfirst($widget) . '/Views')) {
$this->loadViewsFrom(__DIR__. '/'. ucfirst($widget) . '/Views', 'widget.' . $widget);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question