lundi 2 novembre 2015

Laravel 5.1 - Method [middlewere] does not exits

I am trying to add a middleware, but I am getting a strange problem.

What I have done is-

Create a middleware like it-

Middleware/APIMiddleware.php

<?php

namespace App\Http\Middleware;

use Closure;

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

        return $next($request);
    }
}

Then register it in kernel.php

protected $routeMiddleware = [
    'auth'          => \App\Http\Middleware\Authenticate::class,
    'auth.basic'    => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest'         => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'api'           => \App\Http\Middleware\APIMiddleware::class,
];

Now use the 'api' middleware-

<?php
namespace App\Http\Controllers\API\Customer;

//use App\Http\Controllers\Controller;
use App\Http\Controllers\API\APIAuth;

class ListShowingController extends APIAuth
{
    public function __construct()
    {
        $this->middlewere('api');
    }

    public function dummy()
    {
        //return response()->view('welcome');
        $token_length=150;

        return response()->json([
                                    'name' => 'Abigail',
                                    'state' => 'CA',
                                    'states' => array(
                                                        'a' => "SSSSSS",
                                                        'b' => 8
                                                    ),
                                    'access_token' => bin2hex(random_bytes($token_length))
                                ]);
    }
}

And the routes.php is-

<?php

//Routes for mobile API
Route::group([ 'prefix' => 'api/customer', 'namespace' => 'API\Customer'],     function()
{
    //prefix    is for api/customer/{given_url}
    //namespace is for creating folder in controllers folder (API\Customer)
    Route::get('/',
    [
        'as' => 'API.index',
        'uses' => 'ListShowingController@dummy'
    ]);
});

File structure is like this-

enter image description here

I am getting this error-

enter image description here

Can anyone help me please?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire