SHARE
TWEET

Untitled

a guest Oct 4th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  public function store(Request $request)
  3.     {
  4.         $password = str_random(10);
  5.         if ($request->exists('profissional_id')) {
  6.             $p = Profissional::find($request->profissional_id);
  7.             $u = User::find($request->user_id);
  8.             $p->update($request->profissional);
  9.  
  10.  
  11.             if (isset($request->profissional['avatar'])) {
  12.                 $p->avatar = $request->profissional['avatar']->store('images');
  13.             }
  14.             $p->save();
  15.             $u->fill($request->user);
  16.             /*if (!empty($request->user['password'])) {
  17.                 $u->password = bcrypt($request->user['password']);
  18.             }*/
  19.  
  20.  
  21.             $u->save();
  22.             $request->session()->flash('profissional-update-success', 'Registro atualizado com sucesso!');
  23.  
  24.             if(Auth::user()->role->id == 1){
  25.                 return redirect()->route('profissional.index');
  26.             }
  27.             else{
  28.                 return redirect()->route('perfil-usuario.index');
  29.             }
  30.  
  31.  
  32.         } else {
  33.  
  34.             $u = new User();
  35.             $u->name = $request->user['name'];
  36.             $u->email = $request->user['email'];
  37.             $u->password = bcrypt($password);
  38.             $u->api_token = uniqid(time());
  39.             $u->role_id = 2;
  40.             $u->active = 0;
  41.             $u->remember_token = uniqid(time());
  42.             $u->save();
  43.             $p = new Profissional();
  44.             $p->fill($request->profissional);
  45.             $p->user_id = $u->id;
  46.             $p->active = 0;
  47.             if (isset($request->profissional['avatar'])) {
  48.                 $p->avatar = $request->profissional['avatar']->store('images');
  49.             }
  50.             $request->session()->flash('profissional-insert-success', 'Registro inserido com sucesso!');
  51.             $p->save();
  52.             if(Auth::user()->role->id == 1){
  53.                 $u->notify(new NewProfessionalByAdmin($password));
  54.                 return redirect()->route('profissional.index')->with('message', 'Cadastrado com Sucesso ! ! !');
  55.             }
  56.             else{
  57.                 return redirect()->route('perfil-usuario.index')->with('message', 'Cadastrado com Sucesso ! ! !');
  58.             }
  59.  
  60.         }
  61.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top