File manager - Edit - /var/www/payraty/inventory_main/app/Http/Controllers/Admin/WeightUnit/WeightUnitsController.php
Back
<?php namespace App\Http\Controllers\Admin\WeightUnit; use App\Http\Controllers\Controller; use App\DataTables\WeightUnitDataTable; use App\Http\Requests\WeightUnitRequest; use App\Services\WeightUnit\WeightUnitService; use App\Models\WeightUnit; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Illuminate\Http\Request; use PDF; use Excel; use App\Exports\WeightUnitsExport; use Illuminate\Support\Facades\DB; class WeightUnitsController extends Controller { protected $weightUnitService; /** * __construct * * @param mixed $weightUnitService * @return void */ public function __construct(WeightUnitService $weightUnitService) { $this->weightUnitService = $weightUnitService; $this->middleware(['permission:List Weight Unit'])->only(['index']); $this->middleware(['permission:Add Weight Unit'])->only(['create']); $this->middleware(['permission:Edit Weight Unit'])->only(['edit']); $this->middleware(['permission:Delete Weight Unit'])->only(['destroy']); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(WeightUnitDataTable $dataTable) { set_page_meta(__('custom.weight_unit')); $user = Auth::user(); $orgId = $user->organisation_id; $weight_units = WeightUnit::where('organisation_id', $orgId)->paginate(10); // return $dataTable->render('admin.weight_units.index'); $profile = DB::table('profiles')->where('user_id', $user->id)->first(); return view('admin.weight_units.index', compact('weight_units', 'profile')); } public function filter(Request $request) { $user = Auth::user(); $orgId = $user->organisation_id; $period = $request->get('period', 'all'); $query = WeightUnit::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 } $weights = $query->get(); if ($request->ajax()) { return response()->json([ 'weights' => $weights ]); } // Fallback for non-AJAX requests return redirect()->route('admin.weight_units.index'); } public function search(Request $request) { $user = Auth::user(); $orgId = $user->organisation_id; $searchTerm = $request->get('q'); $weights = WeightUnit::where('organisation_id', $orgId) ->where(function ($query) use ($searchTerm) { $query->where('name', 'LIKE', "%{$searchTerm}%"); }) ->get(); if ($request->ajax()) { return response()->json([ 'weights' => $weights ]); } // Fallback for non-AJAX requests return view('admin.weight_units.index', compact('weights')); } /** * exportWeightUnits * * @param mixed $request * @return void */ public function exportWeightUnits(Request $request) { $weight_units = []; $type = $request->type; $user = Auth::user(); $orgId = $user->organisation_id; $weight_units = WeightUnit::where('organisation_id', $orgId)->get(); $name = 'Weight_Unit_' . now()->format('YmdHis'); if ($type == 'pdf') { $pdf = PDF::loadView('admin.weight_units.pdf.index', ['weight_units' => $weight_units]); return $pdf->download($name . '.pdf'); } else if ($type == 'csv') { return Excel::download(new WeightUnitsExport($weight_units), $name . '.csv'); } else if ($type == 'excel') { return Excel::download(new WeightUnitsExport($weight_units), $name . '.xlsx'); } } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { set_page_meta(__('custom.add_weight_unit')); return view('admin.weight_units.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = Auth::user(); $data = [ "name" => $request->name, "organisation_id" => $user->organisation_id ]; try { $weight = WeightUnit::create($data); return redirect()->route('admin.weight-units.index'); } catch (\Exception $e) { flash(__('custom.weight_unit_creation_failed'))->error(); return redirect()->back()->withInput(); } } /** * 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) { $weight_unit = $this->weightUnitService->get($id); set_page_meta(__('custom.edit_weight_unit')); return view('admin.weight_units.edit', compact('weight_unit')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(WeightUnitRequest $request, $id) { $data = $request->validated(); $user = Auth::user(); $orgId = $user->organisation_id; if ($this->weightUnitService->createOrUpdate($orgId, $data, $id)) { flash(__('custom.weight_Unit_updated_successfully'))->success(); } else { flash(__('custom.weight_Unit_update_failed'))->error(); } return redirect()->route('admin.weight-units.index'); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { if ($this->weightUnitService->delete($id)) { flash(__('custom.weight_unit_deleted_successfully'))->success(); } else { flash(__('custom.weight_unit_delete_failed'))->error(); } return redirect()->route('admin.weight-units.index'); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings