Advertisement
Guest User

Untitled

a guest
Jan 12th, 2021
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. // SAVE BANNER IN EMPLOYER MODEL
  2.     public function saveBanner($data) {
  3.         if(isset($data['banner'])) {
  4.             $banner = $data['banner'];
  5.             if(isset($this->banner) && Storage::disk('public')->exists($this->banner)) {
  6.                 Storage::disk('public')->delete($this->banner);
  7.             }
  8.             $path = Storage::disk('public')->put('banners', $banner);
  9.             $this->banner = $path;
  10.         }
  11.     }
  12.  
  13. // UPDATE CONTROLLER
  14.  
  15.     public function update(UpdateEmployerRequest $request) {
  16.         $data = $request->validated();
  17.         $user = getEmployer()->user;
  18.         $employer = getEmployer();
  19.         if(app('hash')->check($request->password, $user->password) === true || auth()->user()->isEmployee()) {
  20.             $employer->saveLogo($data);
  21.             $employer->saveBanner($data);
  22.             $employer->fill($data);
  23.             $employer->save();
  24.             return redirect()->route('employers.edit');
  25.         } else {
  26.             $errors = new \Illuminate\Support\MessageBag();
  27.             $errors->add('password',  __('validation.custom.password_update'));
  28.             return redirect()->route('employers.edit')->withErrors($errors);
  29.         }
  30.  
  31.     }
  32.  
  33. // RULES
  34.  
  35.  
  36. <?php
  37.  
  38. namespace App\Http\Requests;
  39.  
  40. use Illuminate\Foundation\Http\FormRequest;
  41. use App\Rules\PhoneNumber;
  42.  
  43. class UpdateEmployerRequest extends FormRequest
  44. {
  45.     /**
  46.      * Determine if the user is authorized to make this request.
  47.      *
  48.      * @return bool
  49.      */
  50.     public function authorize()
  51.     {
  52.         return true;
  53.     }
  54.  
  55.     /**
  56.      * Get the validation rules that apply to the request.
  57.      *
  58.      * @return array
  59.      */
  60.     public function rules()
  61.     {
  62.         return array_merge([
  63.             'name' => 'required|min:3',
  64.             'description' => 'nullable|min:3',
  65.             'color' => 'nullable|regex:/#[a-fA-F0-9]{6}/',
  66.             'logo' => 'nullable|file|image|max:10000|dimensions:max_height=500,max_width=500',
  67.             'banner' => 'nullable|file|image|max:10000',
  68.             'contact_firstname' => 'required|min:2',
  69.             'contact_lastname' => 'required|min:2',
  70.             'contact_firstname' => 'required|min:2',
  71.             'contact_lastname' => 'required|min:2',
  72.             'civic' => 'required|string',
  73.             'city' => 'required|string',
  74.             'enterprise_number' => 'required|string',
  75.             'revenue' => 'required|numeric',
  76.             'hiring_volume' => 'required|numeric',
  77.             'phone_number' => ['required', new PhoneNumber()],
  78.             'contact_phone_number' => ['required', new PhoneNumber()],
  79.         ]);
  80.     }
  81. }
  82.  
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement