/**
  * Salva a Empresa no BD e redireciona pra home
  * Criando também a prettyUrl associada a essa Empresa
  *
  * @return Response
  */
 public function store()
 {
     $novaEmpresa = Auth::user()->empresas()->create(Request::all());
     $novaPrettyUrl = new PrettyUrl();
     $novaPrettyUrl->tipo = 'empresa';
     //se ja nao existir essa prettyUrl
     $novaPrettyUrl->url = $novaPrettyUrl->giveAvailableUrl($novaEmpresa->nome);
     $novaEmpresa->prettyUrl()->save($novaPrettyUrl);
     return redirect('home');
 }
Beispiel #2
0
 /**
  * Salva a Ong no BD e redireciona pra home, 
  * criando também a prettyUrl associada com essa Ong
  *
  * @return Response
  */
 public function store(CriarOngRequest $request)
 {
     $novaOng = Auth::user()->ongs()->create($request->all());
     $novaOng->responsavel()->associate(Auth::user()->perfil)->push();
     $novaPrettyUrl = new PrettyUrl();
     $novaPrettyUrl->tipo = 'ong';
     $foto = Request::input('foto');
     if ($foto && $foto > 0) {
         $novaOng->fotos()->save(Foto::find($foto));
     }
     $User = Auth::user();
     Mail::send('emails.obrigadoong', ['user' => $User], function ($message) use($User) {
         $message->to($User->email, $User->username)->subject('Olá, tudo bem?');
         $message->from('*****@*****.**', 'Vivalá');
     });
     //se ja nao existir uma ong com essa prettyUrl
     $novaPrettyUrl->url = $novaPrettyUrl->giveAvailableUrl($novaOng->nome);
     $novaOng->prettyUrl()->save($novaPrettyUrl);
     $novaPrettyUrl->push();
     Session::put('entidadeAtiva_id', $novaOng->id);
     Session::put('entidadeAtiva_tipo', 'ong');
     $perfil = $novaOng;
     $follow = $novaOng->followPerfil;
     $followedBy = $novaOng->followedByPerfil;
     $entidadeAtiva = $novaOng;
     $posts = $novaOng->posts;
     return view('perfil.index', compact('user', 'perfil', 'follow', 'followedBy', 'posts', 'entidadeAtiva'));
 }