Home > Enterprise >  Laravel 9.x html form action cannot find view blade file
Laravel 9.x html form action cannot find view blade file

Time:04-09

I want to create a simple login page but I cannot reach my action page on html, I'm not sure about the syntax. I have a function that stores data from the input form but I can't even view the form and laravel shows an error that says this -> ["Action message not defined."].

Here is my code and the error I get;
This Error

web.php

Route::post('/message',[App\Http\Controllers\PagesController::class,'getData']);
Route::view('login','message');

PagesController.php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class PagesController extends Controller
{
    public function getData(Request $Req)
    {
        return $Req->input();
    }
}

message.blade.php

<form action="{{action ('message')}}" method="POST">
@csrf

CodePudding user response:

In order to use the route name, you need to actually name the route:

Route::post('/message',[App\Http\Controllers\PagesController::class,'getData'])->name('message');

And you'll need to change action to route

<form action="{{route('message')}}" method="POST">
  • Related