Exemplo n.º 1
0
 /**
  * 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');
 }
Exemplo n.º 2
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     Validator::extend('pretty_url', function ($attribute, $value, $parameters) {
         $prettyUrl = PrettyUrl::where("url", $value)->get()->first();
         $isMyUrl = $prettyUrl ? $prettyUrl->prettyurlable == Auth::user()->entidadeAtiva : true;
         return $prettyUrl ? $isMyUrl : true;
     });
     return ['nome' => "string|required|min:2", 'descricao' => "string|required|min:2", 'horario_funcionamento' => "string|required|min:2", 'url' => "required|alpha_dash|min:2|pretty_url", 'logradouro' => "string|required|min:2", 'cep' => "required|min:2", 'bairro' => "string|required|min:2", 'complemento' => "string|min:2", 'email_contato' => "email", 'telefone_contato' => "min:8", 'cidade_id' => "required|exists:cidades,id", 'categoria_ong_id' => "required|exists:categoria_ongs,id"];
 }
Exemplo n.º 3
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     Validator::extend('pretty_url', function ($attribute, $value, $parameters) {
         $prettyUrl = PrettyUrl::where("url", $value)->get()->first();
         $isMyUrl = $prettyUrl ? $prettyUrl->prettyurlable == Auth::user()->entidadeAtiva : true;
         return $prettyUrl ? $isMyUrl : true;
     });
     return ["foto_upload" => 'mimes:png,jpg', "nome" => 'date_format:"d/m/Y"', "descricao" => 'alpha|min:3'];
 }
Exemplo n.º 4
0
 public static function getPrettyUrlFor($obj)
 {
     if (!$obj) {
         return 'wrong_object';
     } else {
         dd($obj);
         return PrettyUrl::all()->where('prettyurlable_id', $obj->id)->first()->url;
     }
 }
Exemplo n.º 5
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     Validator::extend('pretty_url', function ($attribute, $value, $parameters) {
         $prettyUrl = PrettyUrl::where("url", $value)->get()->first();
         $isMyUrl = $prettyUrl ? $prettyUrl->prettyurlable == Auth::user()->entidadeAtiva : true;
         return $prettyUrl ? $isMyUrl : true;
     });
     return ["nome" => "required|min:4", "apelido" => "required|min:2", "url" => "required|alpha_dash|min:2|pretty_url"];
 }
Exemplo n.º 6
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     Validator::extend('pretty_url', function ($attribute, $value, $parameters) {
         $prettyUrl = PrettyUrl::where("url", $value)->get()->first();
         $isMyUrl = $prettyUrl ? $prettyUrl->prettyurlable == Auth::user()->entidadeAtiva : true;
         return $prettyUrl ? $isMyUrl : true;
     });
     return ["apelido" => "required|min:2", "url" => "required|string|min:2|pretty_url", "aniversario" => 'required|date_format:"d/m/Y"', "descricao_curta" => 'string', "descricao_longa" => 'string', "cidade_atual" => 'string|min:3'];
 }
Exemplo n.º 7
0
 /**
  * Mostra a ong
  *
  * @param  int  $id
  * @return Response
  */
 public function show($prettyUrl)
 {
     //se o dado da sessao for diferente da prettyUrl digitada, pegar da url
     $ong = Session::get('ong', null);
     if (is_null($ong) || $prettyUrl != $ong->getUrl()) {
         Session::forget('ong');
         $prettyUrlObj = PrettyUrl::all()->where('url', $prettyUrl)->first();
         //Se parametro for uma prettyURL, pegar objeto Ong.
         if (!is_null($prettyUrlObj)) {
             $ong = App\Ong::find($prettyUrlObj->prettyurlable_id);
         } else {
             $ong = App\Ong::find($prettyUrl);
             if (!$ong) {
                 App::abort(404);
             }
         }
     }
     Session::put('perfil', $ong);
     $user = $ong->user;
     $perfil = $ong;
     $follow = $perfil->followPerfil;
     $followedBy = $perfil->followedByPerfil;
     $entidadeAtiva = $perfil;
     $posts = $ong->posts;
     return view('perfil.index', compact('user', 'perfil', 'follow', 'followedBy', 'posts', 'entidadeAtiva'));
 }
Exemplo n.º 8
0
 /**
  * Mostra o perfil de um usuario.
  * @param   String		$prettyUrl       se acessado diretamente, passa a suposta prettyUrl
  * @return  View       	Perfil do usuario em questao
  */
 public function showUserProfile($prettyUrl = null)
 {
     //se nao veio nada na sessao e nem na url
     if (!$prettyUrl && !Session::has('perfil')) {
         App::abort(404);
     }
     //se o dado da sessao for diferente da prettyUrl digitada, pegar da url
     $perfil = Session::get('perfil', null);
     if (is_null($perfil) || $prettyUrl != $perfil->getUrl()) {
         Session::forget('perfil');
         $prettyUrlObj = PrettyUrl::all()->where('url', $prettyUrl)->first();
         //Se parametro for uma prettyURL, pegar objeto Perfil.
         if (!is_null($prettyUrlObj)) {
             $perfil = App\Perfil::find($prettyUrlObj->prettyurlable_id);
         } else {
             if (is_numeric($prettyUrl)) {
                 $perfil = App\Perfil::findOrFail($prettyUrl);
             } else {
                 App::abort(404);
             }
         }
     }
     $user = $perfil->user;
     $follow = $perfil->followPerfil;
     $followedBy = $perfil->followedByPerfil;
     $entidadeAtiva = $perfil;
     $posts = $entidadeAtiva->posts;
     return view('perfil.index', compact('user', 'perfil', 'follow', 'followedBy', 'posts', 'entidadeAtiva'));
 }