I’m facing a persistent 419 error in my Laravel application, which not only affects form submissions but also occurs on the login page. Despite implementing several solutions, the problem persists, and I’m reaching out for help and fresh perspectives.
Here are the steps I’ve taken to address the issue:
- Ensured
@csrf
is Present: I’ve confirmed that the@csrf
directive is present in my forms. - Tried
{{ csrf_field() }}
: I’ve also attempted to use{{ csrf_field() }}
as an alternative. - Adjusted Session Domain: I’ve set the session domain to match the website’s URL.
- Increased Maximum Upload Time: I’ve increased the maximum upload time.
- Reset CageFS: I even went as far as resetting CageFS.
- Replaced TinyMCE with Summernote: Initially, I suspected TinyMCE, so I replaced it with Summernote, but the problem persists.
- Investigated the ‘longtext’ Field: I initially thought the issue might be related to the ‘longtext’ field, but it submitted once and then failed on the very next attempt.
8.included
What’s particularly perplexing is that this 419 error is not limited to form submissions but also occurs on the login page. This leads me to believe that there might be a deeper issue with CSRF token verification or session management.
I would greatly appreciate any insights, suggestions, or solutions from the experienced developers here. If you need specific code snippets, configuration details, or additional information to assist in diagnosing the problem, please feel free to ask, and I’ll provide them promptly.
Thank you immensely for your assistance and expertise.
Edit:
The issue with the 419 error on the login page has been successfully resolved by correcting a session_domain misplacement.
However, I’m still encountering a problem when using the "AddProduct" feature, especially with long text inputs. To restructure the issue:
The "AddProduct" functionality is working well when short text inputs are used, but when I attempt to submit longer text inputs, the application encounters issues. Specifically, when I provide lengthy text in certain fields, the submission fails, resulting in the 419 error.
login page:
<form method="POST" action="{{ route('login') }}">
@csrf
<div class="mb-3">
<label for="login" class="form-label">{{__('Email/Phone/Name')}}</label>
<input class="form-control @error('login') is-invalid @enderror" id="login" type="text" name="login" :value="old('login')" required autofocus>
@error('login')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
<!-- Password -->
<div class="mb-3">
<label for="password" class="form-label">{{__('Password')}}</label>
<div class="input-group input-group-merge">
<input type="password" id="password" class="form-control @error('password') is-invalid @enderror" name="password"
required autocomplete="current-password"/>
<div class="input-group-text" data-password="false">
<span class="password-eye"></span>
</div>
</div>
@error('login')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
<!-- Remember Me -->
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="checkbox-signin" checked name="remember">
<label class="form-check-label" for="checkbox-signin">Remember me</label>
</div>
</div>
<div class="text-center d-grid">
@if (Route::has('password.request'))
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('password.request') }}">
{{ __('Forgot your password?') }}
</a>
@endif
<button class="btn btn-primary" type="submit"> {{ __('Log in') }} </button>
</div>
</form>
AddProduct blade:
<form id="myForm" method="POST" action="{{route('product.store')}}" enctype="multipart/form-data">
{{ csrf_field() }}
<h5 class="mb-4 text-uppercase"><i class="mdi mdi-account-circle me-1"></i> Product Info</h5>
<div class="row">
<div class="col-md-6">
<div class="form-group mb-3">
<label for="name" class="form-label">Product Name</label>
<input type="text" name="product_name" class="form-control @error('product_name') is-invalid @enderror" id="name" >
@error('product_name')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div>
<div class="col-md-6">
<div class="form-group mb-3">
<label for="category" class="form-label">Category </label>
<select name="category_id" class="form-select form-group @error('category_id') is-invalid @enderror" id="example-select">
<option disabled selected >Select Category</option>
@foreach($categories as $category)
<option value="{{$category->id}}">{{$category->category_name}}</option>
@endforeach
</select>
@error('category_id')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-6">
<div class="form-group mb-3">
<label for="supplier" class="form-label">Supplier </label>
<select name="supplier_id" class="form-select @error('supplier_id') is-invalid @enderror" id="example-select">
<option disabled selected>Select Supplier</option>
@foreach($suppliers as $supplier)
<option value="{{$supplier->id}}">{{$supplier->name}}</option>
@endforeach
</select>
@error('supplier')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-6">
<div class="form-group mb-3">
<label for="phone" class="form-label">Buying Price</label>
<input type="text" name="buying_price" class="form-control @error('buying_price') is-invalid @enderror" id="buying_price">
@error('buying_price')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-6">
<div class="form-group mb-3">
<label for="phone" class="form-label">Selling Price</label>
<input type="text" name="selling_price" class="form-control @error('selling_price') is-invalid @enderror" id="selling_price">
@error('selling_price')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-6">
<div class="form-group mb-3">
<label for="phone" class="form-label">Product Quantity</label>
<input type="number" name="product_store" class="form-control @error('product_store') is-invalid @enderror" id="product_store">
@error('product_store')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-6">
<div class="form-group mb-3">
<label for="phone" class="form-label">Selling Price</label>--}}
<input type="text" name="selling_price" class="form-control @error('selling_price') is-invalid @enderror" id="selling_price">
@error('selling_price')--}}
<span class="text-danger"> {{$message}}</span>
@enderror
</div>--}}
</div> <!-- end col -->
<div class="col-md-12">
<div class="form-group mb-3">
<label for="phone" class="form-label">Product Description</label>
<textarea type="text" name="product_description" class="form-control @error('product_description') is-invalid @enderror" id="mysummernote"></textarea>
@error('product_description')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-12">
<div class="form-group mb-3">
<label for="phone" class="form-label">Product Features</label>
<textarea type="text" name="product_features" class="form-control @error('product_features') is-invalid @enderror" id="my2summernote"></textarea>
@error('product_features')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div> <!-- end col -->
<div class="col-md-12">
<div class="form-group mb-3">
<label for="example-fileinput" class="form-label">Product Image</label>
<input type="file" name="product_image" class="form-control" id="image">
</div>
<img id="showImage" src="{{(!empty($product->product_image))? url('upload/product/'.$product->product_image) : url('upload/no_image.jpg')}}" class="rounded-circle avatar-lg img-thumbnail"
alt="profile-image">
</div> <!-- end col -->
</div> <!-- end row -->
<div class="text-end">
<button type="submit" class="btn btn-success waves-effect waves-light mt-2"><i class="mdi mdi-content-save"></i> Save</button>
</div>
</form>
2
Answers
419 is TokenMismatchException .put you route at :routes/web.php