jeudi 30 septembre 2021

Laravel: BadMethodCallException Method post does not exist

Controller:

<?php

namespace App\Http\Controllers; 

use Illuminate\Http\Request;

class AdminController extends Controller
{
    public function index() {
        $title = 'App Name | Login';
        return view('admin.login', compact('title'));
    }

    public function login(Request $request) {
        return $request->input();
    }
}

Route: web.php

<?php 
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminController;
/* 
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('admin', 'AdminController@index')->name('index');
Route::post('admin/login', 'AdminController@login')->name('admin.login');

View:

<form class="form-horizontal" action="" method="POST" novalidate>
    <input type="hidden" name="_token" value="" />
    <input type="text" class="form-control" name="username" placeholder="Your Username" required>
    <input type="password" class="form-control" name="password" placeholder="Enter Password" required>
    <button type="submit" class="btn btn-outline-info btn-block" name="submit">Login</button>
</form>

I am new in laravel and using 5.4 version. Now, What I am going to try when I click on submit button the it go to admin/login page but it throw an error i.e. BadMethodCallException: Method post does not exist. I don't know why this happening? Please help me.

Thank You



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire