0
votes

The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel 8 error used, what I am doing wrong here?

My form file name -- insertemp.blade.php

<form method="POST" action="/showemployee">
   @csrf
   <div class="form-group" style="margin-left: 30px">
      <label for="id">ID</label>
      <input class="form-control"  type="number" name="eid" id="empid"><br>
   </div>
</form>

My web.php

Route::get('/', function () {
   return view('welcome');
});

Route::get('/showemployee',[EmployeeController::class,'show']);
Route::post('/showemployee',[EmployeeController::class,'store']);     

My controller file -- EmployeeController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Employee;

class EmployeeController extends Controller
{
   public function show()
   {
      $emp = Employee::all();

      return view('showemployee',['employees' => $emp]);
   }

   public function store()
   {
       echo "I am in store";
       error_log(request('eid'));

       return redirect('/');
   }
}
1
why don't use the resource controller?dılo sürücü
@dılosürücü I am new to laravel, I am following a tutorial he used basic controllerAbhishek
okay look at my answer ,ı shared code exampledılo sürücü

1 Answers

0
votes
Route::post('/showemployee', [EmployeeController::class,'store'])->name('form.post');

and

<form method="POST" action="{route('form.post')}}" >
    @csrf
    <div class="form-group" style="margin-left:30px">
       <label for="id">ID</label>
       <input class="form-control" type="number" name="eid" id="empid">
    </div>
</form>

if still not works

check with :

php artisan route:list