I have a web app where users can look at different postings and apply to the ones they want.
However when a user is not authenticated and he presses on the "Apply" Button, he then gets redirected to the Login window. After Logging in he SHOULD get redirected to the post he pressed the "Apply" Button.
Right now he just gets redirected, as normal, to the overview of posts.
I have no idea how to google stuff on it, since I don't know what this kind of redirection is called.
Any help appreciated
CodePudding user response:
After trying around a little bit and failing a lot, I finally found a solution!
First I get the previous URL like this:
$url = url()->previous()
then I get the part of the url after the / like this:
$id = substr($url, strrpos($url, '/') 1);
In the login controller I check what the url contains, if it contains the specific route the user has to come from to not get redirected to the standard after login page I do this:
if (str_contains($url, 'bewerben')) {
return redirect()->to('/bewerben/' . $id);
}
The bewerben route looks like this in my web.php file:
Route::get('/bewerben/{post}', [PostController::class, 'getDetails'])->name('details')->middleware('portal');
This is why I needed the $id
If the user comes from every other previous url I just redirect him to the standard after login page:
else {
return redirect()->intended(route('overview'));
}
