You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					61 lines
				
				2.1 KiB
			
		
		
			
		
	
	
					61 lines
				
				2.1 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace App\Http\Controllers\Vendor;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use App\Http\Controllers\Controller;
							 | 
						||
| 
								 | 
							
								use App\Models\Category;
							 | 
						||
| 
								 | 
							
								use Brian2694\Toastr\Facades\Toastr;
							 | 
						||
| 
								 | 
							
								use Illuminate\Http\Request;
							 | 
						||
| 
								 | 
							
								use Illuminate\Support\Facades\DB;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class CategoryController extends Controller
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    function index()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $categories=Category::where(['position'=>0])->latest()->paginate(config('default_pagination'));
							 | 
						||
| 
								 | 
							
								        return view('vendor-views.category.index',compact('categories'));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function get_all(Request $request){
							 | 
						||
| 
								 | 
							
								        $data = Category::where('name', 'like', '%'.$request->q.'%')->limit(8)->get([DB::raw('id, CONCAT(name, " (", if(position = 0, "'.translate('messages.main').'", "'.translate('messages.sub').'"),")") as text')]);
							 | 
						||
| 
								 | 
							
								        if(isset($request->all))
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            $data[]=(object)['id'=>'all', 'text'=>'All'];
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return response()->json($data);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    function sub_index()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $categories=Category::with(['parent'])->where(['position'=>1])->latest()->paginate(config('default_pagination'));
							 | 
						||
| 
								 | 
							
								        return view('vendor-views.category.sub-index',compact('categories'));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function search(Request $request){
							 | 
						||
| 
								 | 
							
								        $key = explode(' ', $request['search']);
							 | 
						||
| 
								 | 
							
								        $categories=Category::where(function ($q) use ($key) {
							 | 
						||
| 
								 | 
							
								            foreach ($key as $value) {
							 | 
						||
| 
								 | 
							
								                $q->orWhere('name', 'like', "%{$value}%");
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        })->limit(50)->get();
							 | 
						||
| 
								 | 
							
								        return response()->json([
							 | 
						||
| 
								 | 
							
								            'view'=>view('vendor-views.category.partials._table',compact('categories'))->render(),
							 | 
						||
| 
								 | 
							
								            'count'=>$categories->count()
							 | 
						||
| 
								 | 
							
								        ]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function sub_search(Request $request){
							 | 
						||
| 
								 | 
							
								        $key = explode(' ', $request['search']);
							 | 
						||
| 
								 | 
							
								        $categories=Category::with(['parent'])->where(function ($q) use ($key) {
							 | 
						||
| 
								 | 
							
								            foreach ($key as $value) {
							 | 
						||
| 
								 | 
							
								                $q->orWhere('name', 'like', "%{$value}%");
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        })->where(['position'=>1])->limit(50)->get();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        return response()->json([
							 | 
						||
| 
								 | 
							
								            'view'=>view('vendor-views.category.partials._sub_table',compact('categories'))->render(),
							 | 
						||
| 
								 | 
							
								            'count'=>$categories->count()
							 | 
						||
| 
								 | 
							
								        ]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |