Try
return Redirect::back()->withErrors(['insufficient' => 'You do not have enough coins to proceed']);
@if($errors->any())
{{$errors->first()}}
@endif
I was wondering, how can I set the error message and the key so I can get in the blade using @error directive? I'm trying this way: return redirect()->back()->withErrors(['insufficient' => 'You do not have enough coins to proceed']); but it's not seeting the insufficient only the message error.
@zfdeveloper Hey man, i tried here and error directive works without problem. When i submit the form, the store method on controller returns the expected message!
In my routes file
Route::get('/', 'SomeController@index');
Route::post('/store', 'SomeController@store');
In my SomeController
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Redirect;
class SomeController extends Controller
{
public function index()
{
return view('index');
}
public function store()
{
return Redirect::back()->withErrors(['insufficient' => 'You do not have enough coins to proceed']);
}
}
In my index view
<form method="POST" action="/store">
@csrf
@error('insufficient')
{{ $message }}
@enderror
<input type="submit" value="Submit">
</form>
Please or to participate in this conversation.