Guest User

Untitled

a guest
Oct 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public function handle($request, Closure $next, $rotaSolicitada){
  2.  
  3. try{
  4. $usuario = JWTAuth::parseToken()->authenticate();
  5. }catch (Exception $e){
  6. return response()->json(['error'=> true, 'mensagem'=> 'Não foi possível autenticar no sistema', 'data'=> null], 500);
  7. }
  8.  
  9. $permissao = Perfil::with('usuario')
  10. ->where('id', $usuario->id)
  11. ->where('recursos->links->rota', 'reserva')
  12. ->get();
  13.  
  14. //aqui é só para exibir o retorno (teste)
  15. dump($permissao);
  16. return response()->json($permissao);
  17.  
  18.  
  19.  
  20. $recursoSolicitado = str_replace( '@','',strstr($request->route()->getActionName(), '@'));
  21.  
  22.  
  23. return $next($request);
  24. }
  25.  
  26. public function up()
  27. {
  28. Schema::create('perfis', function (Blueprint $table) {
  29. $table->increments('id');
  30. $table->string('descricao', 45);
  31. $table->json('recursos')->nullable();
  32. $table->char('status',1);
  33. $table->timestamps();
  34. });
  35. }
  36.  
  37. {"links":
  38. [
  39. {
  40. "rota": "reserva", "sref": "oQueFazer", "ordem": "1", "recursos": ["index", "show"], "descricao": "Reservar"
  41. },
  42. {
  43. "rota": "reserva", "sref": "oQueFazer", "ordem": "2", "recursos": ["index", "show"], "descricao": "Reservas"
  44. },
  45. {
  46. "rota": "usuario", "sref": "oQueFazer", "ordem": "3", "recursos": ["index", "show"], "descricao": "Usuários"},
  47. {
  48. "rota": "feriado", "sref": "oQueFazer", "ordem": "4", "recursos": ["index", "show"], "descricao": "Feriados"},
  49. {
  50. "rota": "sala", "sref": "home.sala", "ordem": "5", "recursos": ["index", "show"], "descricao": "Salas"
  51. }
  52. ]
  53. }
  54.  
  55. $permissao = Perfil::with('usuario')
  56. ->where('id', $usuario->id)
  57. ->where('recursos->links->rota', 'reserva')
  58. ->get();
Add Comment
Please, Sign In to add comment