php artisan make:provider AdminComposerServiceProvider
register that provider in config/app.php
'providers' => [App\Providers\AdminComposerServiceProvider::class,]
in Providers/AdminComposerServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AdminComposerServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
View::composer('layouts.app','App\Http\View\AdminViewComposer');
//
}
}
create new file adminViewComposer.php inside App\Http\View
and paste below code
<?php
namespace App\Http\View;
use App\MessageSend;
use Illuminate\View\View;
class AdminViewComposer
{
public function compose(View $view)
{
// $view->with('count', $this->users->count());
$view->with('message',MessageSend::orderBy('id','DESC')->take(5)->get());
}
}

$data['products'] = QueryBuilder::for(Product::class)->whereHas('thumbnail')->with('thumbnail')->whereHas('discount')->with('discount')
ReplyDelete->allowedFilters(
[
AllowedFilter::exact('brand', 'brand'),
AllowedFilter::exact('location', 'city_id'),
AllowedFilter::exact('user', 'user_id'),
AllowedFilter::exact('category', 'category_id'),
AllowedFilter::exact('categories', 'category.parent_id'),
AllowedFilter::scope('price'),
AllowedFilter::scope('search'),
],
)
->allowedSorts(['name', 'id'])->where('is_draft', false)->paginate(20)
->appends(request()->query());
// if ($request->slug) {
// $data['categories_sidebar'] = Category::whereParentId(Category::whereSlug($request->slug)->pluck('id'))
// ->with('descendants')
// ->select('id', 'name')
// ->get();
// } else {
// $data['categories_sidebar'] = Category::whereParentId(Category::whereSlug('market')->pluck('id'))
// ->with('descendants')
// ->select('id', 'name')
// ->get();
// }
if ($request->has('filter.categories')) {
$data['categories_sidebar'] = Category::whereIn('parent_id', explode(',', $request->input('filter.categories')))
->with('descendants')
->select('id', 'name')
->get();
} elseif ($request->has('filter.category')) {
$data['categories_sidebar'] = Category::whereIn('id', explode(',', $request->input('filter.category')))
->with('descendants')
->select('id', 'name')
->get();
} else {
$data['categories_sidebar'] = Category::whereParentId(Category::whereSlug('market')->pluck('id'))
->with('descendants')
->select('id', 'name')
->get();
}
Post a Comment