Home > other >  Laravel 8 validation doesn't work and it redirects me to "419|page expired"
Laravel 8 validation doesn't work and it redirects me to "419|page expired"

Time:09-17

I'm just new to laravel and I couldn't understand why the error message of validation won't display and it redirect instead to "419|page expired" , even after following a video tutorial and the laravel documentation.

*This is the html code

<form action="{{ route('registerPost') }}" method="post">
        <!-- full name div -->
        <div class="flex mt-2 gap-2">
            <div class="w-1/2">
                <label for="">First Name</label><br>
                <input id="firstName" class="w-full px-2 py-1 border border-gray-300 rounded-md focus:outline-none focus:border-green-500" type="text" name="firstName" value="">
            </div>
            @error('firstName')
            <div class="text-sm text-red">{{ $message }}</div>
            @enderror
            <div class="w-1/2">
                <label for="">Last Name</label><br>
                <input class="w-full px-2 py-1 border border-gray-300 rounded-md focus:outline-none focus:border-green-500" type="text" name="lastName" value="">
            </div>
        </div>

*The route

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\createController;


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

Route::get('/register', [createController::class, 'index'])->name('register');
Route::post('/register', [createController::class, 'store'])->name('registerPost');


*Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class createController extends Controller
{
    public function index(){
        return view('register');
    }

    public function store(Request $request)
    {
        
        $validated = $request->validate([
            'firstName' => 'required|max:30',
            'lastName' => 'required|max:30',
            'email' => 'required|max:30',
            'username' => 'required|max:30',
            'password' => 'required|max:30'
        ]);

    }
}


CodePudding user response:

try to add .

{{ csrf_field() }}

CodePudding user response:

Add @csrf Or {{ csrf_field() }} into the form tag

CodePudding user response:

The @csrf works guys. Thanks everyone.

  • Related