Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

AutorizacaoMiddleware não encontrado

Erro

ReflectionException in Container.php line 779:
Class estoque\Http
\Middleware\AutorizacaoMiddleware does not exist
in Container.php line 779
at ReflectionClass->__construct('estoque\Http \Middleware\AutorizacaoMiddleware') in Container.php line 779
at Container->build('estoque\Http \Middleware\AutorizacaoMiddleware', array()) in Container.php line 659
at Container->make('estoque\Http \Middleware\AutorizacaoMiddleware', array()) in Application.php line 644
at Application->make('estoque\Http \Middleware\AutorizacaoMiddleware') in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(ProdutoController), object(Route), object(Request), 'novo') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'estoque\Http\Controllers\ProdutoController', 'novo') in Route.php line 204
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 701
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 703
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 670
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/Users/silvanioduartedacruz/estoque/public/index.php') in server.php line 21

Kernel

<?php namespace estoque\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel {

    /**
     * The application's global HTTP middleware stack.
     *
     * @var array
     */
    protected $middleware = [
        'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
        'Illuminate\Cookie\Middleware\EncryptCookies',
        'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
        'Illuminate\Session\Middleware\StartSession',
        'Illuminate\View\Middleware\ShareErrorsFromSession',
        'estoque\Http\Middleware\VerifyCsrfToken',

    ];

    /**
     * The application's route middleware.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => 'estoque\Http\Middleware\Authenticate',
        'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
        'guest' => 'estoque\Http\Middleware\RedirectIfAuthenticated',
        'nosso-middleware' => 'estoque\Http
        \Middleware\AutorizacaoMiddleware',
    ];

}

AutorizacaoMiddleware

<?php namespace estoque\Http\Middleware;

use Closure;

class AutorizacaoMiddleware {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if(!$request->is('auth/login') && \Auth::guest()){
                return redirect('/auth/login');
        }

        return $next($request);

    }

}

ProdutoController

<?php

  namespace estoque\Http\Controllers;
  use Illuminate\Support\Facades\DB;
  use Request;
  use Validator;
  use estoque\Produto;
  use estoque\Http\Requests\ProdutosRequest;

  class ProdutoController  extends Controller {

      //Contstrutor
      public function __construct()
      {
          $this -> middleware('nosso-middleware',['only' => ['novo','remove']]);
      }
3 respostas

Olá Silvânio,

O nome do arquivo também se chama AutorizacaoMiddleware.php ? e ele está na pasta estoque\Http\Controllers ?

Se você usou o Composer, tente o comando: composer dump-autoload dentro da pasta do projeto.

Att,

solução!

Ramon encontrei o erro.

Parece brincadeira mais quando criei a Rota do Middleware eu afiz desta forma : 'nosso-middleware' => 'estoque\Http \Middleware \AutorizacaoMiddleware',.

Observe que á um espaço após o Http, este era o erro.

Pior q eu vi, mas achei q era coisa do editor. rsrs.

Que bom q você achou o erro.

Att,