it-swarm.com.de

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException Keine Nachricht

Das macht meinen Kopf rein. Ich bekomme diese Fehlermeldung, wenn ich mich von einem Formular aus anmelden möchte:

Symfony\Component\HttpKernel\Exception \ 

MethodNotAllowedHttpException 

Keine Nachricht

LoginController.php

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
    use AuthenticatesUsers;
    protected $username = 'username';
    protected $redirectTo = '/dashboard';
    protected $guard = 'web';
    public function getLogin()
    {
        if (Auth::guard('web')->check())
        {
            return redirect()->route('dashboard');
        }
        return view('login');
    }
    public function postLogin(Request $request)
    {
        $auth = Auth::guard('web')->attempt(['username' => $request->username, 'password' => $request->password, 'active' => 1]);
        if ($auth)
        {
            return redirect()->route('dashboard');
        }
        return redirect()->route('/');
    }
    public function getLogout()
    {
        Auth::guard('web')->logout();
        return redirect()->route('/');
    }
}

Die folgende Route funktioniert gut, wenn ich ein Formular übermittle.

Route::get('/', ['as' => '/', 'uses' => '[email protected]']);
Route::get('/login', ['as' => 'login', 'uses' => '[email protected]']);

Route::group(['middleware' => ['autheticates', 'roles']], function (){
    Route::get('/logout', ['as' => 'logout', 'uses' => '[email protected]']);
    Route::get('/dashboard', ['as' => 'dashboard', 'uses' => '[email protected]']);
});

Middleware/Autheticates.php

class Autheticates
{
    public function handle($request, Closure $next, $guard = 'web')
    {
        if (!Auth::guard($guard)->check())
        {
            return redirect()->route('/');
        }
        return $next($request);
    }
}

Middleware/Rollen.php

class Roles
{
    public function handle($request, Closure $next)
    {
        $roles = $this->getRequiredRoleForRoute($request->route());
        if ($request->user()->hasRole($roles) || $roles){
            return $next($request);
        }
        return redirect()->route('noPermissions');
    }
    private function getRequiredRoleForRoute($route)
    {
        $actions = $route->getAction();
        return isset($actions['roles']) ? $actions['roles'] : null;
    }
}

login.blade.php

<form class="login-form" action="{{ route('login') }}" method="post">
    {{ csrf_field() }}
    <div class="login-wrap">
        <p class="login-img"><i class="icon_lock_alt"></i></p>
        <div class="input-group">
            <span class="input-group-addon"><i class="icon_profile"></i></span>
            <input type="text" name="username" class="form-control" placeholder="Username" autofocus>
        </div>
        <div class="input-group">
            <span class="input-group-addon"><i class="icon_key_alt"></i></span>
            <input type="password" name="password" class="form-control" placeholder="Password">
        </div>
        <label class="checkbox">
            <input type="checkbox" value="remember-me"> Remember me
            <span class="pull-right"> <a href="#"> Forgot Password?</a></span>
        </label>
        <button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
        <button class="btn btn-info btn-lg btn-block" type="reset">Signup</button>
    </div>
</form>

 Error Image

6
user9085794

Fehler in der von Ihnen definierten Route. Seine get und sollte sich in post ändern.

ändere das

Route::get('/login', ['as' => 'login', 'uses' => '[email protected]']);

zu diesem

Route::post('/login', ['as' => 'login', 'uses' => '[email protected]']);

action="{{ route('login') }}" # form Submit action
4
Abdulla Nilam

ihre Antwort der Route sollte sein

Route::post('/login', ['as' => 'login', 'uses' => '[email protected]']);
0
danoj.I