관리-도구
편집 파일: JobpostController.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 Carbon\Carbon; use App\Models\BlogCategory; class JobpostController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data = Jobpost::where('is_active',1)->simplePaginate(9); return view('backend.blogs.index',['data'=>$data]); } public function showPinnedJobs() { $pinnedJobs = Jobpost::where('pinned_jobs', 1)->get(); return view('theme.saintsaccessories.index', compact('pinnedJobs')); } public function editsin($id) { $job = Jobpost::find($id); return view('theme.saintsaccessories.update_job', ['job' => $job, 'id' => $id]); } public function upload(Request $request) { $request->validate([ 'csv_file' => 'required|mimes:csv,txt', ]); $file = $request->file('csv_file'); $csvData = file_get_contents($file); $rows = array_map('str_getcsv', explode("\n", $csvData)); $header = array_shift($rows); foreach ($rows as $row) { if (count($header) != count($row)) { continue; } $jobData = array_combine($header, $row); JobPost::create([ 'job_title' => $jobData['job_title'], 'job_description' => $jobData['job_description'], 'keywords' => $jobData['keywords'], 'min_experience' => $jobData['min_experience'], 'max_experience' => $jobData['max_experience'], 'min_salary' => $jobData['min_salary'], 'max_salary' => $jobData['max_salary'], 'company_name' => $jobData['company_name'], 'workplace_type' => $jobData['workplace_type'], 'job_location' => $jobData['job_location'], 'job_type' => $jobData['job_type'], 'no_of_vacancy' => $jobData['no_of_vacancy'], 'industry' => $jobData['industry'], 'qualification' => $jobData['qualification'], 'contact_person' => $jobData['contact_person'], 'mobile' => $jobData['mobile'], 'job_post_expiry_date' => $jobData['job_post_expiry_date'], 'empolyer_designation' => $jobData['empolyer_designation'], 'employer_contact' => $jobData['employer_contact'], 'employer_email' => $jobData['employer_email'], 'link_space' => $jobData['link_space'], 'status' => $jobData['status'], 'created_at' => now(), 'updated_at' => now(), ]); } return redirect()->back()->with('success', 'CSV Uploaded Successfully!'); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ 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_country = $request->job_country; $data->job_city = $request->job_city; $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; $data->empolyer_designation = $request->empolyer_designation; $data->employer_contact = $request->employer_contact; $data->employer_email = $request->employer_email; $data->link_space = $request->link_space; $data->pinned_jobs = $request->pinned_jobs; $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!"); } } public function deleteJobsWithoutCompanyName() { // Get all unique company names from job posts $companyNames = JobPost::select('company_name')->distinct()->pluck('company_name'); foreach ($companyNames as $companyName) { // Check if the company name exists in the users table $userExists = User::where('company_name', $companyName)->exists(); // If the company name does not exist in the users table, delete the job posts if (!$userExists) { JobPost::where('company_name', $companyName)->delete(); } } return response()->json(['message' => 'Job posts without a corresponding company name in the users table have been deleted.']); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $productsData = Blog::all()->where('id',(int)$id); $singleData= ''; foreach($productsData as $sData) { $singleData = $sData; } return view('backend.blogs.show',['singleData'=>$singleData,'id'=>$id]); } public function showCreateForm() { return view('backend.blogs.createform'); } // 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 filteredJobs(Request $request) { // dd($request->all()); $query = Jobpost::query(); // Filter by job_type $query->when($request->job_type, function($q) use ($request) { return $q->where('job_type', 'LIKE', '%' . $request->job_type . '%'); }); // Filter by experience_level $query->when($request->experience_level, function($q) use ($request) { 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); } }); // Filter by estimated_salary $query->when($request->estimated_salary, function($q) use ($request) { 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); } }); // Filter by location $query->when($request->location, function($q) use ($request) { if ($request->location != '') { return $q->where('job_location', 'LIKE', '%' . $request->location . '%'); } }); // Filter by job_country $query->when($request->job_country, function($q) use ($request) { return $q->where('job_country', 'LIKE', '%' . $request->job_country . '%'); }); // Filter by job_city $query->when($request->job_city, function($q) use ($request) { return $q->where('job_city', 'LIKE', '%' . $request->job_city . '%'); }); $jobs = $query->simplePaginate(8); 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')->skip(1)->take(6)->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) { // Get the job post by ID $data = Jobpost::findOrFail($id); // Check if the job post exists if (!$data) { return redirect('/')->with('error', 'Job post not found.'); } // Show the job post details return view('theme.saintsaccessories.job_details', ['data' => $data]); } // public function singleJob($id) // { // // Get the job post by ID // $data = Jobpost::where('id', $id)->first(); // // Check if the job post exists // if (!$data) { // return redirect('/')->with('error', 'Job post not found.'); // } // // Check if the job post has expired // $now = Carbon::now(); // if (Carbon::parse($data->job_post_expiry_date)->isPast()) { // // Delete the expired job post // $data->delete(); // // Redirect with a message indicating the job post has expired // return redirect('/')->with('error', 'The job post has expired and is no longer available.'); // } // // If the job post is not expired, show it // 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){ // Find the job post by its ID $data = Jobpost::find($id); // Check if the job post exists if(!$data) { return redirect()->back()->with("error", "Job Post not found!"); } // Update the job post details $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; $data->empolyer_designation = $request->empolyer_designation; $data->employer_contact = $request->employer_contact; $data->employer_email = $request->employer_email; $data->link_space = $request->link_space; $data->pinned_jobs = $request->pinned_jobs; // Save the updated data $save = $data->save(); // Redirect back with success or error message if($save){ return redirect()->back()->with("success", "Job Updated successfully"); } else { return redirect()->back()->with("error","Sorry! Job couldn't be updated!"); } } public function storeJobApplications(Request $request) { // Validate the file input $request->validate([ 'resume' => 'required|mimes:pdf,doc,docx|max:2048', // Limit file size to 2MB ]); // Save the job application $data = new Jobapplication(); $data->user_id = $request->user_id; $data->job_id = $request->job_id; $data->status = 0; // Handle resume upload if ($request->hasFile('resume')) { $file = $request->file('resume'); $resumePath = $file->store('public/resumes'); // Store the file in 'storage/app/public/resumes' $data->resume_path = $resumePath; // Save the path in the database } $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"; $companyEmail = (Company::where('company_name', $job->company_name)->first())->company_email ?? ''; if ($companyEmail != '') { // Uncomment the following line to send the email // Mail::to($companyEmail)->send(new GeneralMail($mail)); } return redirect(url('/'))->with("success", "You Have Successfully Applied To This Job"); } else { return redirect(url('/'))->with("error", "Sorry! couldn't apply!"); } } 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) { $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!'); } } }