관리-도구
편집 파일: CompanyController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Company; use App\Models\BlogCategory; use Illuminate\Support\Facades\Mail; use App\Mail\GeneralMail; use App\User; use Hash; class CompanyController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data = Company::where('is_active',1)->simplePaginate(9); return view('backend.blogs.index',['data'=>$data]); } /** * 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 */ // old code begin // public function store(Request $request) // { // $data = new Company(); // $data->first_name = $request->firstname; // $data->last_name = $request->lastname; // $data->company_name = $request->companyname; // $data->company_phone = $request->companyphone; // $data->company_email = $request->companyemail; // $data->company_tagline = $request->companytagline; // $data->company_details = $request->companydetails; // $data->company_industry = $request->companyindustry; // $data->company_profile_image = $request->companyprofileimage; // $data->company_banner_image = $request->companybannerimage; // $data->company_password = $request->companypassword; // $data->employe_role = $request->employrole?? ''; // $data->no_of_employees = $request->noofemployee?? ''; // $data->billing_address1 = $request->billingaddress1; // $data->billing_address2 = $request->billingaddress2; // $data->billing_country = $request->billingcountry; // $data->billing_city = $request->billingcity; // $data->billing_state = $request->billingstate; // $data->billing_zip = $request->billingzip; // $data->street_address = $request->streetaddress; // $data->address = $request->companyaddress2?? ''; // $data->country = $request->companycountry; // $data->city = $request->companycity; // $data->state = $request->companystate; // $data->zip = $request->companyzip; // // $data->agreement = $request->agreement; // // dd($request->all()); // // $data=$request->except('_token'); // 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; // } // if($request->hasFile('companybannerimage')){ // // foreach($request->file('companybannerimage') as $image) // // { // $name=$request->file('companybannerimage')->getClientOriginalName(); // $request->file('companybannerimage')->move(public_path().'/uploads/companybanners/', $name); // // $img = $name; // // } // $data->company_banner_image = $name; // } // if(User::where('email',$request->companyemail)->first()){ // return redirect(url('/company_sign_up'))->with("error","This Email Is Already Registered!, Use Anyother Email"); // }else{ // if(User::where('name',$request->companyname)->first()){ // return redirect(url('/company_sign_up'))->with("error","This Company Name Is Already Registered!,Login To Continue"); // }else{ // $save = $data->save(); // } // } // // $save= $data->save(); // // $save = Company::create($data); // if($save){ // { // $profile_picture = "default.png"; // // if($request->hasfile('companyprofileimage')) // // { // // $file = $request->file('companyprofileimage'); // // $profile_picture = time().$file->getClientOriginalName(); // // $file->move(public_path()."/uploads/profile/", $profile_picture); // // } // $user = new User(); // $user->name = $request->companyname; // $user->email = $request->companyemail; // $user->user_type = 'company'; // // $user->role_id = $request->role_id; // $user->status = 1; // $user->profile_picture = $profile_picture; // $user->email_verified_at = date('Y-m-d H:i:s'); // $user->password = Hash::make($request->companypassword); // $userSave = $user->save(); // //Prefix Output // $user->status = status($user->status); // $user->user_type = ucwords($user->user_type); // $user->profile_picture = '<img src="' . profile_picture($user->profile_picture) . '" class="thumb-sm rounded-circle mr-2">'; // if($userSave){ // return redirect(url('/sign_in'))->with("success", "Company profile has been created successfully"); // }else{ // return redirect(url('/'))->with("error","Sorry! Company profile couldn't be created!"); // } // } // return redirect(url('/sign_in'))->with("success", "Company's profile has been created successfully"); // }else{ // return redirect(url('/'))->with("error","Sorry! Company's profile couldn't be created!"); // } // } // old code End public function store(Request $request){ $data = new Company(); $data->first_name = $request->firstname; $data->last_name = $request->lastname; $data->company_name = $request->companyname; $data->company_phone = $request->companyphone; $data->company_email = $request->companyemail; $data->company_tagline = $request->companytagline; $data->company_details = $request->companydetails; $data->company_industry = $request->companyindustry; $data->company_profile_image = $request->companyprofileimage; $data->company_banner_image = $request->companybannerimage; $data->company_password = $request->companypassword; $data->employe_role = $request->employrole ?? ''; $data->no_of_employees = $request->noofemployee ?? ''; $data->billing_address1 = $request->billingaddress1; $data->billing_address2 = $request->billingaddress2; $data->billing_country = $request->billingcountry; $data->billing_city = $request->billingcity; $data->billing_state = $request->billingstate; $data->billing_zip = $request->billingzip; $data->street_address = $request->streetaddress; $data->address = $request->companyaddress2 ?? ''; $data->country = $request->companycountry; $data->city = $request->companycity; $data->state = $request->companystate; $data->zip = $request->companyzip; if ($request->hasFile('companyprofileimage')) { $name = $request->file('companyprofileimage')->getClientOriginalName(); $request->file('companyprofileimage')->move(public_path('/uploads/companyprofiles/'), $name); $data->company_profile_image = $name; } if ($request->hasFile('companybannerimage')) { $name = $request->file('companybannerimage')->getClientOriginalName(); $request->file('companybannerimage')->move(public_path('/uploads/companybanners/'), $name); $data->company_banner_image = $name; } if (User::where('email', $request->companyemail)->first()) { return redirect(url('/company_sign_up'))->with("error", "This Email Is Already Registered! Use Another Email."); } elseif (User::where('name', $request->companyname)->first()) { return redirect(url('/company_sign_up'))->with("error", "This Company Name Is Already Registered! Login To Continue."); } $save = $data->save(); if ($save) { $user = new User(); $user->name = $request->companyname; $user->email = $request->companyemail; $user->user_type = 'company'; $user->status = 0; // Default: Pending approval $user->profile_picture = 'default.png'; $user->password = Hash::make($request->companypassword); $userSave = $user->save(); if ($userSave) { // Send approval email to admin $adminEmail = 'findjobs@eraas.org'; // Replace with admin's email Mail::send('mail.admin_approval', ['user' => $user], function ($message) use ($adminEmail) { $message->to($adminEmail) ->subject('New Company Registration Pending Approval'); }); return redirect(url('/sign_in'))->with("success", "Company profile created successfully. Please wait for admin approval."); } else { return redirect(url('/'))->with("error", "Sorry! Company profile couldn't be created!"); } } return redirect(url('/'))->with("error", "Sorry! Company profile couldn't be created!"); } /** * 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) { $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 filteredCompanies(Request $request) { $query = Company::query(); $query->when(request('keyword'),function($q){ return $q->where('company_industry','LIKE',"%request('keyword')%"); }); $query->when(request('city'),function($q){ return $q->where('city',request('city')); }); $query->when(request('location'),function($q){ if(request('location') != ''){ return $q->where('address','LIKE',"%request('location')%"); } }); $companies = $query->get(); // $companies = Company::where('status',1)->where('city','LIKE',"%$request->city%")->where('address', 'LIKE', "%$request->location%")->get(); return view("theme.saintsaccessories.employer_services")->with('filteredCompanies',$companies);; } public function getLatestBlogs() { $latestBlogs = Blog::where('is_active',1)->orderby('created_at','desc')->limit(2)->get(); return $latestBlogs; } public function getRandomBlogs() { $randomBlogs = Blog::where('is_active',1)->orderby('created_at','desc')->skip(2)->take(Blog::count()-2)->get(); return $randomBlogs; } static public function getBlogCategories() { $blogCategory = BlogCategory::orderby('created_at','desc')->get(); return $blogCategory; } public function singleCompanyProfile($companyname) { // Fetch the company data based on the dynamic company name $data = Company::where('company_name', $companyname)->first(); // Pass the data to the view return view('theme.saintsaccessories.employe_profile', ['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) { $data=$request->all(); $result=Blog::find($request->id); if($request->hasFile('image')){ foreach($request->file('image') as $image) { $name=$image->getClientOriginalName(); $image->move(public_path().'/theme/default/images/', $name); $img[] = $name; } $data['image'] = json_encode($img); } $save=$result->fill($data)->save(); if($save){ return redirect(route('blogcms'))->with("success",'Data Updated Succesfully'); }else{ return redirect(route('blogcms'))->with("error",'Error Ocuured Data is not Updated!'); } } public function updateCompany(Request $request){ $data=$request->all(); $company=Company::find($request->extra); if($request->hasFile('companybannerimage')){ $name=$request->file('companybannerimage')->getClientOriginalName(); $request->file('companybannerimage')->move(public_path().'/uploads/companyprofiles/', $name); $company['company_banner_image'] = $name; } if($request->hasFile('companyprofileimage')){ $name=$request->file('companyprofileimage')->getClientOriginalName(); $request->file('companyprofileimage')->move(public_path().'/uploads/companybanners/', $name); $company['company_profile_image'] = $name; } $company->first_name = $request->firstname; $company->last_name = $request->lastname; // $company->company_name = $request->companyname; $company->company_tagline = $request->companytagline; $company->company_details = $request->companydetails; $company->company_phone = $request->companyphone; $company->company_email = $request->companyemail; $company->billing_address1 = $request->billingaddress1; $company->billing_address2 = $request->billingaddress2; $company->billing_country = $request->billingcountry; $company->billing_city = $request->billingcity; $company->billing_state = $request->billingstate; $company->billing_zip = $request->billingzip; $company->street_address = $request->streetaddress; $company->address = $request->companyaddress2 ; $save=$company->save(); if($save){ return redirect('/')->with("success",'Data Updated Succesfully'); }else{ return redirect('/')->with("error",'Error Ocuured Data is not Updated!'); } } public function employRoundtableForm(Request $request){ $mail = new \stdClass(); $mail->subject = 'Employer Roundtable Interview Signup Form'; $mail->content = $request->except('_token'); Mail::to('findjobs@customdev.devopdigital.com')->send(new GeneralMail($mail)); return redirect()->back()->with('success','Thanks,Request Submitted Successfully'); } public function candidateRoundtableForm(Request $request){ $mail = new \stdClass(); $mail->subject = 'Candidate Roundtable Interview Request Form'; $mail->content = $request->except('_token'); Mail::to('findjobs@customdev.devopdigital.com')->send(new GeneralMail($mail)) ; return redirect()->back()->with('success','Thanks, Request Submitted Successfully'); } /** * 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!'); } } }