Файловый менеджер - Редактировать - /home/clickysoft/public_html/benchexc.clickysoft.net/app/Repositories/OpportunitiesRepository.php
Назад
<?php namespace App\Repositories; use App\Http\Resources\OpportunityResource; use App\Interfaces\OpportunitiesRepositoryInterface; use App\Models\MultiOrgTechStack; use App\Models\opportunity; use Illuminate\Support\Facades\Validator; class OpportunitiesRepository implements OpportunitiesRepositoryInterface { const ERROR_HAS_OCCURRED = 'Error has occurred.'; public function getAllOpportunities(): \Illuminate\Http\Resources\Json\AnonymousResourceCollection { $user = auth()->user(); $Opportunity = opportunity::where('user_id',$user ->id)->get(); return OpportunityResource::collection($Opportunity); } public function createOpportunities($request): OpportunityResource|\Illuminate\Http\JsonResponse { $user= auth()->user(); if (!$user){ return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 404, [], [['User not found.']]); } $validator = Validator::make($request->all(), [ 'title' => 'required|string|max:255', 'description' => 'required|string', 'years_of_experience' => 'required|integer|min:0', 'pay_scale' => 'nullable|string|max:255', 'application_deadline' => 'nullable|date_format:d/m/Y', 'addition_notes' => 'nullable|string', 'city_id' => 'required|integer|exists:cities,id', 'email'=>'required|email', 'company_name'=>'required|max:255', 'phone_number'=>'required', 'location'=>'required' ]); if ($validator->fails()) { return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 422, [], collect($validator->errors())->values()->map(fn($error) => $error)); } $record = opportunity::create([ 'title'=>$request->title, 'description'=>$request->description, 'years_of_experience'=>$request->years_of_experience, 'pay_scale'=>$request->pay_scale, 'application_deadline'=>$request->application_deadline, 'addition_notes'=>$request->addition_notes, 'city_id'=>$request->city_id, 'user_id'=>$user->id, 'opportunity_type'=>$request->opportunity_type, 'email'=>$request->email, 'company_name'=>$request->company_name, 'phone_number'=>$request->phone_number, 'location'=>$request->location ]); foreach ($request->tech_stacks_id as $tech_stacks_id){ MultiOrgTechStack::create([ 'opportunities_id'=>$record->id, 'tech_stacks_id'=>$tech_stacks_id ]); } return new OpportunityResource($record); } public function updateOpportunities($request,$id): OpportunityResource|\Illuminate\Http\JsonResponse { $opportunity = opportunity::where('id',$id)->first(); if (!$opportunity){ return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 404, [], [['Opportunity not found.']]); } $validator = Validator::make($request->all(), [ 'title' => 'required|string|max:255', 'description' => 'required|string', 'years_of_experience' => 'required|integer|min:0', 'pay_scale' => 'nullable|string|max:255', 'application_deadline' => 'nullable|date', 'addition_notes' => 'nullable|string', 'city_id' => 'required|integer|exists:cities,id', 'location'=>'required' ]); if ($validator->fails()) { return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 422, [], collect($validator->errors())->values()->map(fn($error) => $error)); } $opportunity->update([ 'title'=>$request->title, 'description'=>$request->description, 'years_of_experience'=>$request->years_of_experience, 'pay_scale'=>$request->pay_scale, 'application_deadline'=>$request->application_deadline, 'addition_notes'=>$request->addition_notes, 'city_id'=>$request->city_id, 'opportunity_type'=>$request->opportunity_type, 'location'=>$request->location ]); $opportunity_teckStack = MultiOrgTechStack::where('opportunities_id',$opportunity->id)->first(); foreach ($request->tech_stacks_id as $tech_stacks_id){ $opportunity_teckStack->update([ 'opportunities_id'=>$opportunity->id, 'tech_stacks_id'=>$tech_stacks_id ]); } return new OpportunityResource($opportunity); } public function destroyOpportunities($id,$request): \Illuminate\Http\JsonResponse { $opportunity = opportunity::where('id',$id)->first(); if (!$opportunity){ return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 404, [], [['Opportunity not found.']]); }else $opportunity->delete(); return response()->json(['success , opportunity is deleted']); } public function changeStatus($id, $request): \Illuminate\Http\JsonResponse { $opportunity = opportunity::where('id', $id)->first(); if (!$opportunity){ return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 404, [], [['Opportunity not found.']]); } $opportunity->update([ 'status'=> $request->status ]); return response()->json(['success , Status is changed']); } public function getAllData(): \Illuminate\Http\Resources\Json\AnonymousResourceCollection { $user = auth()->user(); $resources = opportunity::where('user_id', '!=', $user->id)->get(); return OpportunityResource::collection($resources); } public function filterSearch($request) { $resource = opportunity::whereBetween('years_of_experience', [$request->start_date, $request->end_date])->get(); return response()->json([ 'year' => $resource, ]); } public function viewOpportunity($request ,$id) { $opportunity = opportunity::where('id',$id)->first(); if (!$opportunity) { return makeJsonResponse('error', self::ERROR_HAS_OCCURRED, 404, [], [['Opportunity not found.']]); } return response(new OpportunityResource($opportunity)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка