function insertProvider(Request $request) { $this->validate($request, ['location' => 'required', 'address' => 'required', 'contact' => 'required', 'contact-phone' => 'required', 'description' => 'required', 'NIT' => 'required', 'company-name' => 'required', 'licence' => 'required', 'logo' => 'required', 'taxpayer' => 'required'], ['location.required' => 'Debe agregar al menos una ubicación', 'address.required' => 'La dirección es requerida', 'contact.required' => 'El nombre de contacto es requerido', 'contact-phone.required' => 'El Teléfono de contacto es requerido', 'description.required' => 'La descripción es requerida', 'NIT.required' => 'El número del NIT es requerido', 'company-name' => 'El nombre de la empresa es requerido', 'licence' => 'Es necesario que adjunte su licencia de ventas', 'logo' => 'Debe adjuntar el logo de la empresa', 'taxpayer' => 'El tipo de contribuyente es requerido']); $user = Auth::user(); $provider = Provider::where('user_id', $user->id)->first(); $files = $request->file(); $provider->update($request->all()); foreach ($files as $key => $file) { $fileName = str_random(40) . '**' . $request->file($key)->getClientOriginalName(); $request->file($key)->move(base_path() . '/public/uploads/providers/', $fileName); $provider[$key] = $fileName; } $provider->save(); return redirect()->route('admin'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, $validate) { $user = Auth::user(); if ($validate == 'registerProvider') { $provider = Provider::where('user_id', '=', $user->id)->get(); if (!$provider->isEmpty()) { return redirect()->route('admin'); } } if ($validate == 'validateProvider') { if ($user->role_id != 3 || $user->validate != 0) { return redirect()->route('admin'); } } return $next($request); }
function insertProvider(Request $request) { $this->validate($request, ['location' => 'required', 'address' => 'required', 'contact' => 'required', 'contact-phone' => 'required', 'description' => 'required', 'NIT' => 'required', 'company-name' => 'required', 'licence' => 'required', 'logo' => 'required', 'taxpayer' => 'required'], ['location.required' => 'Debe agregar al menos una ubicación', 'address.required' => 'La dirección es requerida', 'contact.required' => 'El nombre de contacto es requerido', 'contact-phone.required' => 'El Teléfono de contacto es requerido', 'description.required' => 'La descripción es requerida', 'NIT.required' => 'El número del NIT es requerido', 'company-name' => 'El nombre de la empresa es requerido', 'licence' => 'Es necesario que adjunte su licencia de ventas', 'logo' => 'Debe adjuntar el logo de la empresa', 'taxpayer' => 'El tipo de contribuyente es requerido']); $user = Auth::user(); $provider = Provider::where('user_id', $user->id)->first(); $files = $request->file(); $provider->update($request->all()); foreach ($files as $key => $file) { $fileName = str_random(40) . '**' . $request->file($key)->getClientOriginalName(); $request->file($key)->move(base_path() . '/public/uploads/users/', $fileName); $provider[$key] = $fileName; } $user['photo'] = $provider['logo']; $user->save(); $provider->save(); Notification::create(['user_id' => $provider->agent()->first()->user_id, 'text' => 'El proveedor ' . $provider['company-name'] . ' ha completado el segundo formulario', 'url' => route('showUser', $user->id)]); Mail::send('emails.registerProvider', ['user' => $user], function ($m) use($user) { $m->to($user->email, $user->name)->subject('Casi finaliza tu registro!'); }); return redirect()->route('admin'); }
function validateProvider($id) { $provider = Provider::where('user_id', $id)->first(); if ($provider->validate) { $provider->validate = 0; } else { $provider->validate = 1; } $provider->save(); Mail::send('emails.validateProvider', ['user' => $provider->user], function ($m) use($provider) { $m->to($provider->user->email, $provider->user->name)->subject('Ya eres un proveedor!'); }); return redirect()->route('providers'); }