File manager - Edit - /var/www/payraty/inventory_main/app/Http/Controllers/Admin/Brand/BrandsController.php
Back
<?php namespace App\Http\Controllers\Admin\Brand; use App\DataTables\BrandDataTable; use App\Http\Requests\BrandRequest; use App\Http\Controllers\Controller; use App\Services\Brand\BrandService; use App\Models\Brand; use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; use PDF; use Excel; use App\Exports\BrandsExport; use Illuminate\Support\Facades\DB; class BrandsController extends Controller { protected $brandService; /** * __construct * * @param mixed $brandService * @return void */ public function __construct(BrandService $brandService) { $this->brandService = $brandService; $this->middleware(['permission:List Brand'])->only(['index']); $this->middleware(['permission:Add Brand'])->only(['create']); $this->middleware(['permission:Edit Brand'])->only(['edit']); $this->middleware(['permission:Delete Brand'])->only(['destroy']); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(BrandDataTable $dataTable) { set_page_meta(__('custom.brand')); $user = Auth::user(); $orgId = $user->organisation_id; $brands = Brand::where('organisation_id', $orgId)->paginate(10); //return $dataTable->render('admin.brands.index'); $profile = DB::table('profiles')->where('user_id', $user->id)->first(); return view('admin.brands.index', compact('brands', 'profile')); } /** * exportBrands * * @param mixed $request * @return void */ public function exportBrands(Request $request) { $brands = []; $type = $request->type; $user = Auth::user(); $orgId = $user->organisation_id; $brands = Brand::where('organisation_id', $orgId)->get(); $name = 'Brand_' . now()->format('YmdHis'); if ($type == 'pdf') { $pdf = PDF::loadView('admin.brands.pdf.index', ['brands' => $brands]); return $pdf->download($name . '.pdf'); } else if ($type == 'csv') { return Excel::download(new BrandsExport($brands), $name . '.csv'); } else if ($type == 'excel') { return Excel::download(new BrandsExport($brands), $name . '.xlsx'); } } public function filter(Request $request) { $user = Auth::user(); $orgId = $user->organisation_id; $period = $request->get('period', 'all'); $query = Brand::where('organisation_id', $orgId); switch ($period) { case 'monthly': $query->whereMonth('created_at', now()->month); break; case 'yearly': $query->whereYear('created_at', now()->year); break; // 'all' case doesn't need additional filtering } $brands = $query->paginate(10); if ($request->ajax()) { return response()->json([ 'brands' => $brands ]); } // Fallback for non-AJAX requests return redirect()->route('admin.brands.index'); } public function search(Request $request) { $user = Auth::user(); $orgId = $user->organisation_id; $searchTerm = $request->get('q'); $brands = Brand::where('organisation_id', $orgId) ->where(function ($query) use ($searchTerm) { $query->where('name', 'LIKE', "%{$searchTerm}%") ->orWhere('desc', 'LIKE', "%{$searchTerm}%"); }) ->paginate(10); if ($request->ajax()) { return response()->json([ 'brands' => $brands ]); } // Fallback for non-AJAX requests return view('admin.brands.index', compact('brands')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { set_page_meta(__('custom.add_brand')); return view('admin.brands.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(BrandRequest $request) { $data = $request->validated(); if ($this->brandService->createOrUpdateWithFile($data, 'image')) { flash(__('custom.brand_create_successful'))->success(); } else { flash(__('custom.brand_create_failed'))->error(); } return redirect()->route('admin.brands.index'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $brand = $this->brandService->get($id); set_page_meta(__('custom.edit_brand')); return view('admin.brands.edit', compact('brand')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(BrandRequest $request, $id) { $data = $request->validated(); if ($this->brandService->createOrUpdateWithFile($data, 'image', $id)) { flash(__('custom.brand_updated_successful'))->success(); } else { flash(__('custom.brand_updated_failed'))->error(); } return redirect()->route('admin.brands.index'); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { if ($this->brandService->delete($id)) { flash(__('custom.brand_deleted_successful'))->success(); } else { flash(__('custom.brand_deleted_failed'))->error(); } return redirect()->route('admin.brands.index'); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings