Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel 9 with argument 2 must be of type ?callable, string given

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 class="alert alert-success">
        <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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading