Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SAVE BANNER IN EMPLOYER MODEL
- public function saveBanner($data) {
- if(isset($data['banner'])) {
- $banner = $data['banner'];
- if(isset($this->banner) && Storage::disk('public')->exists($this->banner)) {
- Storage::disk('public')->delete($this->banner);
- }
- $path = Storage::disk('public')->put('banners', $banner);
- $this->banner = $path;
- }
- }
- // UPDATE CONTROLLER
- public function update(UpdateEmployerRequest $request) {
- $data = $request->validated();
- $user = getEmployer()->user;
- $employer = getEmployer();
- if(app('hash')->check($request->password, $user->password) === true || auth()->user()->isEmployee()) {
- $employer->saveLogo($data);
- $employer->saveBanner($data);
- $employer->fill($data);
- $employer->save();
- return redirect()->route('employers.edit');
- } else {
- $errors = new \Illuminate\Support\MessageBag();
- $errors->add('password', __('validation.custom.password_update'));
- return redirect()->route('employers.edit')->withErrors($errors);
- }
- }
- // RULES
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- use App\Rules\PhoneNumber;
- class UpdateEmployerRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- *
- * @return bool
- */
- public function authorize()
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules()
- {
- return array_merge([
- 'name' => 'required|min:3',
- 'description' => 'nullable|min:3',
- 'color' => 'nullable|regex:/#[a-fA-F0-9]{6}/',
- 'logo' => 'nullable|file|image|max:10000|dimensions:max_height=500,max_width=500',
- 'banner' => 'nullable|file|image|max:10000',
- 'contact_firstname' => 'required|min:2',
- 'contact_lastname' => 'required|min:2',
- 'contact_firstname' => 'required|min:2',
- 'contact_lastname' => 'required|min:2',
- 'civic' => 'required|string',
- 'city' => 'required|string',
- 'enterprise_number' => 'required|string',
- 'revenue' => 'required|numeric',
- 'hiring_volume' => 'required|numeric',
- 'phone_number' => ['required', new PhoneNumber()],
- 'contact_phone_number' => ['required', new PhoneNumber()],
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement