0

how i have to write redirect rout for redirect after save tournament to my new tournament site.

Thanks

This doesnt work

return redirect()->route('tournaments.show', $tournament->slug);

Controller

    public function store(Request $request)
{
    $tournament = new Tournament();
    $tournament->title = $request->title;
    $tournament->city = $request->city;
    $tournament->street = $request->street;
    $tournament->game_room = $request->game_room;
    $tournament->email = $request->email;
    $tournament->registration_link = $request->registration_link;
    $tournament->text = $request->text;
    $tournament->phone = $request->phone;
    $tournament->time_registration_at = $request->time_registration_at;
    $tournament->date_registration_at = $request->date_registration_at;
    $tournament->time_starter_at = $request->time_starter_at;
    $tournament->date_starter_at = $request->date_starter_at;
    $tournament->user_id = Auth::user()->id;
    $tournament->region_id = $request->region_id;
    $tournament->slug = SlugService::createSlug(Tournament::class, 'slug', $request->title);
    $tournament->save();

    return redirect()->back();
}
Tom_hutka
  • 15
  • 4

1 Answers1

0

This is incorrect if using resource controller,

return redirect()->route('tournaments.show', $tournament->slug);

it should be

return redirect()->route('tournaments.show', ['tournament'=>$tournament->slug]);

provided that your routeKeyName for your route model binding is set to use a slug and not an id in the model or using the new laravel route model binding in web.php

Route::resource('tournaments',TournamentController::class)->parameters([
            'tournament'=>'tournaments:slug'
        ]);
spartyboy
  • 428
  • 4
  • 12