Sound complicated... but I probably will use target attribute to open new window
<a href="https://www.w3schools.com" target="_blank">Visit W3Schools!</a>
Or modal....
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I am creating my own redirection tool for my website. So I can enter the link /out/hair and it would redirect to www.hairproduct.com. I was able to get it working using the code below. However I am now on the mission to have it open the redirected page in a new window. I know that I will need to use JS in the view to accomplish this but I am struggling just getting data back into my view.
Here is how I have it
My controller
public function store(Request $request)
{
$request->validate([
'internal' => 'required|unique:redirects|',
]);
Redirect::create([
'internal' => request('internal'),
'external' => request('external'),
]);
return back();
}
public function show(redirect $redirect)
{
$temp = $redirect->external;
return redirect($temp);
}
In my redirect.php I have
public function getRouteKeyName()
{
return 'internal';
}
and in my routes I do
Route::GET('/out/{redirect}', 'RedirectController@show')->name('redirect-link');
I think I need to adjust my public function show() to look something like this
public function show(redirect $redirect)
{
$temp = $redirect->external;
return redirect()->back()->with('temp');
}
Then in the blade file have JS that is watching for a temp variable and then create a new blank window with that variables url. Is this how you would go about this or am I making this the wrong way? If so, how would I setup the redirect with data and the JS? I have tried sending data back but have had no luck. I am not that experienced in JS (more in vue) so I don't know how to watch for the variable and create a new window with the url.
I figured it out! in my controller I have
public function show(redirect $redirect)
{
$newUrl = $redirect->external;
session()->flash('newurl', $newUrl);
return redirect()->back();
}
Then in my blade file I have
@if (session()->has('newurl'))
<redirect-user :newurl="'{{ session('newurl') }}'"></redirect-user>
@endif
And in my vue redirect-user file I have
beforeMount(){
window.open(this.newurl, "_blank");
},
It works great!
Please or to participate in this conversation.