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 index()
 {
     $notifications = Notification::where('user_id', Auth::user()->id)->paginate(8);
     return view('back.notification', compact('notifications'));
 }
示例#3
0
 public function compose(View $view)
 {
     $notify['count'] = Notification::whereRaw('isOpen = 0 and user_id = ' . Auth::user()->id)->count();
     $notify['notifications'] = Notification::where('user_id', Auth::user()->id)->take(10)->get();
     $view->with('notify', $notify);
 }
示例#4
0
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $user = $this->create($request->all());
     if ($user->role_id == 3) {
         $agent = Agent::with('providers')->get()->sortBy(function ($agent) {
             return $agent->providers()->count();
         })->first();
         $provider = new Provider();
         $provider->agent_id = $agent->id;
         $provider->user_id = $user->id;
         $provider->save();
         Notification::create(['user_id' => $agent->user_id, 'text' => 'Se ha registrado un proveedor', 'url' => route('searchProvider')]);
     } else {
         Mail::send('emails.welcome', ['user' => $user], function ($m) use($user) {
             $m->to($user->email, $user->name)->subject('Bienvenido a Agrosellers!');
         });
     }
     auth()->loginUsingId($user->id);
     return redirect($this->redirectPath());
 }