I'm following a tutorial. In the controller I'm using with to send a success message.
public function store(Request $request)
{
$request->validate([
'recipe' => 'required',
'rating' => 'required',
]);
Recipe::create($request->all());
return redirect()->route('recipes.index')
-with('success', 'Recipe created successfully');
}
I'm getting an error message once the form is submitted and I'm redirected to the index page the code there looks like this.
@if ($message = Illuminate\Support\Facades\Session::get('success'))
<div >
<p>{{ $message }}</p>
</div>
@endif
This is the error message: with(): Argument #2 ($callback) must be of type ?callable, string given, called in C:\laragon\www\recipe_project\app\Http\Controllers\RecipeController.php on line 49
CodePudding user response:
You missed arrow:
return redirect()->route('recipes.index')
-with('success', 'Recipe created successfully');
Should be:
return redirect()->route('recipes.index')
->with('success', 'Recipe created successfully');