File manager - Edit - /var/www/html/spdc/api/app/Http/Services/TransportationService.php
Back
<?php namespace App\Http\Services; use App\Models\Transportation; use Illuminate\Http\Request; use Illuminate\Support\Carbon; use Illuminate\Http\JsonResponse; use App\Http\Requests\TransportationRequest; use App\Classes\BaseServiceResponse; use App\Http\Resources\TransportationResource; use Illuminate\Support\Facades\Cache; use App\Http\Resources\TransportationCollection; class TransportationService extends BaseService { public function index(Request $request): BaseServiceResponse { $query = Transportation::query(); if ($request->has('category')) { $query = $query->where('category', strtoupper($request->category)); } if ($request->has('search_term')) { $searchTerm = trim(strtolower($request->search_term)); $query = $query->whereRaw("LOWER(model) LIKE ?", ['%' . $searchTerm . '%']); } $transportations = $query->paginate(15); // Load the transportation data with the "vehicleType" and sorted "status" relationship $transportations->load([ 'vehicleType', 'status' => function ($statusQuery) { $statusQuery->orderBy('created_at', 'desc'); }, ]); return $this->response( TransportationResource::collection($transportations) ); } public function store(TransportationRequest $request): BaseServiceResponse { $transportation = Transportation::create($request->all()); return $this->response( new TransportationResource($transportation->load(['vehicleType'])), JsonResponse::HTTP_CREATED ); } public function show(Transportation $transportation): BaseServiceResponse { // Load the transportation data with the "vehicleType" and sorted "status" relationship $transportation->load([ 'vehicleType', 'status' => function ($query) { $query->orderBy('created_at', 'desc'); }, ]); return $this->response( new TransportationResource($transportation), JsonResponse::HTTP_OK ); } public function update(TransportationRequest $request, Transportation $transportation): BaseServiceResponse { $transportation->fill($request->all()); $transportation->save(); // Load the transportation data with the "vehicleType" and sorted "status" relationship $transportation->load([ 'vehicleType', 'status' => function ($query) { $query->orderBy('created_at', 'desc'); }, ]); return $this->response( new TransportationResource($transportation), JsonResponse::HTTP_OK ); } public function updateStatus(Request $request, Transportation $transportation): BaseServiceResponse { $transportation->status()->create([ 'user_id' => $request->has('user') ? $request->user['id'] : null, 'name' => $request->status, 'note' => $request->note, ]); // Load the transportation data with the "vehicleType" and sorted "status" relationship $transportation->load([ 'vehicleType', 'status' => function ($query) { $query->orderBy('created_at', 'desc'); }, ]); return $this->response( new TransportationResource($transportation), JsonResponse::HTTP_OK ); } public function destroy(Transportation $transportation): BaseServiceResponse { $transportation->delete(); return $this->response( null, JsonResponse::HTTP_NO_CONTENT ); } public function destroyMany(Request $request): BaseServiceResponse { Transportation::destroy(treatArrayInput($request->transportations)); return $this->response( null, JsonResponse::HTTP_NO_CONTENT ); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings