Reputation: 21
There have been a few iterations of this code but I will only show what has worked best so far (no errors).
Destroy Function:
public function destroy($locale, $id)
{
Component::where('id', $id)->delete();
$locale = App::getLocale();
return route('components.index', compact('locale'));
}
Index Function (referenced above):
public function index($locale)
{
parent::lang($locale);
$components = Component::paginate(10);
return view('production/index-component', compact('components'));
}
Relevant Route:
Route::group(['prefix' => '{locale}'], function() {
Route::resource('/components', ComponentController::class);
});
The destroy function works otherwise, records are deleted (upon going to the correct URL). Ideally this should simply redirect the user back to {locale}/components.
Thank you in advance!
Upvotes: 1
Views: 58
Reputation: 21
Credit to lagbox,
public function destroy($locale, $id)
{
Component::where('id', $id)->delete();
$locale = App::getLocale();
return redirect()->route('components.index', ['locale' => $locale]);
}
This worked perfectly.
Upvotes: 1