관리-도구
편집 파일: JobController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Mail; use App\Models\Jobpost; use App\Models\Jobapplication; use App\Mail\GeneralMail; use App\User; use App\Models\Company; use App\Models\BlogCategory; class JobController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data = Jobpost::all(); return view('backend.job.index',['data'=>$data]); } public function show($id) { $job_detail = Jobpost::where('id', $id)->first(); $appliers = Jobapplication::where('job_id', $id)->with('user')->get(); // Debug applicants to confirm user data // dd($appliers); return view('backend.job.show', [ 'job_detail' => $job_detail, 'appliers' => $appliers, ]); } public function store(Request $request) { // dd($request->all()); $data = new Jobpost(); $data->job_title = $request->job_title; $data->job_description = $request->job_description; $data->keywords = $request->keywords; $data->min_experience = $request->min_experience; $data->max_experience = $request->max_experience; $data->min_salary = $request->min_salary; $data->max_salary = $request->max_salary; $data->company_name = $request->company_name; $data->workplace_type = $request->workplace_type; $data->job_location = $request->job_location; $data->job_type = $request->job_type?? ''; $data->no_of_vacancy = $request->no_of_vacancy?? ''; $data->industry = $request->industry; $data->qualification = $request->qualification?? ''; $data->contact_person = $request->contact_person?? ''; $data->mobile = $request->mobile?? ''; $data->job_post_expiry_date = $request->jobpost_expirydate; // if($request->hasFile('companyprofileimage')){ // // foreach($request->file('companyprofileimage') as $image) // // { // $name=$request->file('companyprofileimage')->getClientOriginalName(); // $request->file('companyprofileimage')->move(public_path().'/uploads/companyprofiles/', $name); // // $img = $name; // // } // $data->company_profile_image = $name; // } $save= $data->save(); if($save){ return redirect(url('/'))->with("success", "Job Posted successfully"); }else{ return redirect(url('/'))->with("error","Sorry! Job couldn't be posted!"); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $job = Jobpost::find($id); if (!$job) { return redirect()->back()->with("error", "Job post not found!"); } return view('backend.job.update', ['job' => $job, 'id' => $id]); } public function editsin($id) { $job = Jobpost::find($id); return view('theme.saintsaccessories.update_job', ['job' => $job, 'id' => $id]); } public function filteredJobs(Request $request) { // dd($request->all()); $query = Jobpost::query(); $query->when(request('job_type'),function($q){ return $q->where('job_type','LIKE',"%request('job_type')%"); }); $query->when(request('experience_level'),function($q){ if(request('experience_level')=='Experienced'){ return $q->where('min_experience',3)->where('max_experience','>=',5); }elseif(request('experience_level')=='Mid-level'){ return $q->where('min_experience',2)->where('max_experience',4); }elseif(request('experience_level')=='Junior'){ return $q->where('min_experience',1)->where('max_experience',2); } }); $query->when(request('estimated_salary'),function($q){ if(request('estimated_salary')=='5000-Above'){ return $q->where('max_salary','>=',5000); }elseif(request('estimated_salary')=='3000-5000'){ return $q->where('max_salary','<=',5000); }elseif(request('estimated_salary')=='1000-3000'){ return $q->where('max_salary','<=',3000); }elseif(request('estimated_salary')=='1-1000'){ return $q->where('max_salary','<=',1000); } }); $query->when(request('location'),function($q){ if(request('location') != ''){ return $q->where('job_location','LIKE',"%request('location')%"); } }); $jobs = $query->simplepaginate(8); // $companies = Company::where('status',1)->where('city','LIKE',"%$request->city%")->where('address', 'LIKE', "%$request->location%")->get(); return view("theme.saintsaccessories.all_jobs")->with('filteredJobs',$jobs);; } public function filteredJobsHome(Request $request) { // dd($request->all()); $query = Jobpost::query(); $query->when(request('keyword'), function ($q) { $keyword = request('keyword'); $q->where(function ($subQ) use ($keyword) { $subQ->where('keywords', 'LIKE', '%' . $keyword . '%') ->orWhere('job_title', 'LIKE', '%' . $keyword . '%'); }); }); $query->when(request('location'), function ($q) { if (request('location') !== '') { $q->where('job_location', 'LIKE', '%' . request('location') . '%'); } }); $jobs = $query->simplepaginate(8); // $companies = Company::where('status',1)->where('city','LIKE',"%$request->city%")->where('address', 'LIKE', "%$request->location%")->get(); return view("theme.saintsaccessories.all_jobs")->with('filteredJobs',$jobs);; } public function filteredJobsHomeKeyword(Request $request) { // dd($request->all()); $query = Jobpost::query(); $query->when(request('keyword'),function($q){ return $q->where('keywords','LIKE',"%request('keyword')%"); }); $jobs = $query->simplepaginate(8); // $companies = Company::where('status',1)->where('city','LIKE',"%$request->city%")->where('address', 'LIKE', "%$request->location%")->get(); return view("theme.saintsaccessories.all_jobs")->with('filteredJobs',$jobs);; } public function getLatestBlogs() { $latestBlogs = Blog::where('is_active',1)->orderby('created_at','desc')->limit(2)->get(); return $latestBlogs; } static public function getProfileImage($companyName) { $data = (Company::where('company_name',$companyName)->first())->company_profile_image; return $data; } static public function getRandomJobs() { $randomJobs = Jobpost::orderby('created_at','desc')->latest()->take(8)->get(); return $randomJobs; } static public function getBlogCategories() { $blogCategory = BlogCategory::orderby('created_at','desc')->get(); return $blogCategory; } public function singleCompanyProfile($companyname) { $data= Jobpost::where('company_name',$companyname)->first(); return view('theme.saintsaccessories.employe_profile',['data'=>$data]); } public function singleJob($id) { $data= Jobpost::where('id',$id)->first(); return view('theme.saintsaccessories.job_details',['data'=>$data]); } static public function getAllKeyword() { $keywords = Jobpost::get('keywords'); if(count($keywords) == 0){ return null; } foreach($keywords as $keyword){ foreach(explode(',',$keyword->keywords) as $singleKeyword) { $allKeywords[] = $singleKeyword; } } return $allKeywords; // return view('theme.saintsaccessories.job_details',['data'=>$data]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $job = Jobpost::find($id); if (!$job) { return redirect()->back()->with("error", "Job post not found!"); } $job->job_title = $request->input('job_title'); $job->job_description = $request->input('job_description'); $job->keywords = $request->input('keywords'); $job->min_experience = $request->input('min_experience'); $job->max_experience = $request->input('max_experience'); $job->min_salary = $request->input('min_salary'); $job->max_salary = $request->input('max_salary'); $job->company_name = $request->input('company_name'); $job->workplace_type = $request->input('workplace_type'); $job->job_location = $request->input('job_location'); $job->job_type = $request->input('job_type'); $job->no_of_vacancy = $request->input('no_of_vacancy'); $job->industry = $request->input('industry'); $job->qualification = $request->input('qualification'); $job->contact_person = $request->input('contact_person'); $job->mobile = $request->input('mobile'); $job->job_post_expiry_date = $request->input('job_post_expiry_date'); // If there's a new company profile image, handle file upload if ($request->hasFile('company_profile_image')) { $name = $request->file('company_profile_image')->getClientOriginalName(); $request->file('company_profile_image')->move(public_path().'/uploads/companyprofiles/', $name); $job->company_profile_image = $name; } $job->save(); return redirect()->route('jobposts.edit', $id)->with("success", "Job post updated successfully"); } public function updateindividual(Request $request, $id){ $job = Jobpost::find($id); if (!$job) { return redirect()->back()->with("error", "Job post not found!"); } $validatedData = $request->validate([ 'job_title' => 'required|string|max:255', 'job_description' => 'required|string', 'keywords' => 'nullable|string', 'min_experience' => 'nullable|integer', 'max_experience' => 'nullable|integer', 'min_salary' => 'nullable|numeric', 'max_salary' => 'nullable|numeric', 'company_name' => 'required|string|max:255', 'workplace_type' => 'nullable|string', 'job_location' => 'required|string|max:255', 'job_type' => 'required|string|max:255', 'no_of_vacancy' => 'required|integer', 'industry' => 'nullable|string', 'qualification' => 'nullable|string', 'contact_person' => 'nullable|string|max:255', 'mobile' => 'nullable|string|max:20', 'job_post_expiry_date' => 'nullable|date', 'company_profile_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048', ]); $job->fill($validatedData); if ($request->hasFile('company_profile_image')) { $name = time() . '-' . $request->file('company_profile_image')->getClientOriginalName(); $request->file('company_profile_image')->move(public_path('/uploads/companyprofiles/'), $name); $job->company_profile_image = $name; } $job->save(); return redirect()->route('home')->with('success', 'Job post updated successfully!'); } public function storeJobApplications(Request $request) { // dd($request->all()); $data = new Jobapplication(); $data->user_id = $request->user_id; $data->job_id = $request->job_id; $data->status = 0; $save= $data->save(); if($save){ $job = Jobpost::where('id',$request->job_id)->first(); $user = User::where('id',$request->user_id)->first(); $mail = new \stdClass(); $mail->subject = "Job Application"; $mail->body = "<a href='user-profile/'".$user->id.">".$user->name."</a> has applied on the job(<a href='company_detail/'".$job->id.">".$job->job_title."</a>) that you posted"; // $mail->applicant_name = $user->name; // $mail->applicant_phone = $user->phone; // $mail->applicant_email = $user->email; // $mail->applicant_id = $user->id; // $mail->job_title = $job->job_title; // $mail->job_description = $job->job_description; // $mail->job_post_expiry_date = $job->job_post_expiry_date; $companyEmail = (Company::where('company_name',$job->company_name)->first())->company_email ?? ''; if($companyEmail != ''){ Mail::to('contactus@eraas.org')->send(new GeneralMail($mail)); } //get_option('email') return redirect(url('/'))->with("success", "You Have Successfully Applied To This Job"); }else{ return redirect(url('/'))->with("error","Sorry! couldn't applied!"); } } static public function checkAlreadyApplied($jobid) { $user = Jobapplication::where('job_id',$jobid)->where('user_id',Auth::user()->id)->first(); return $user; } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // Find the job post by ID $jobPost = Jobpost::find($id); // Check if the job post exists if ($jobPost) { // Delete the job post $jobPost->delete(); // Redirect back with a success message return redirect()->back()->with('success', 'Job post deleted successfully.'); } else { // Redirect back with an error message if the job post is not found return redirect()->back()->with('error', 'Job post not found.'); } } public function bulkDelete(Request $request) { $selectedJobs = $request->input('selected_jobs'); if ($selectedJobs) { Jobpost::whereIn('id', $selectedJobs)->delete(); // Delete selected jobs } return redirect()->route('job.index')->with('success', 'Selected job posts deleted successfully.'); } // public function destroy($id) // { // $result = Blog::where('id',$id)->delete(); // if($result){ // return redirect(route('blogcms'))->with("success",'Blog Removed Succesfully'); // }else{ // return redirect(route('blogcms'))->with("error",'Error Ocuured Blog is not Removed!'); // } // } }