To open a link in a new tab using a controller function in Laravel, you can utilize the target attribute in the HTML anchor tag. Here’s an example:
In your controller, you can define a function that returns the URL you want to open in a new tab:
public function openLinkInNewTab()
{
$url = "https://example.com"; // Replace with your desired URL
return view('open_link', compact('url'));
}
In your open_link.blade.php view file, you can generate the anchor tag with the target attribute set to _blank:
// In html
<a href="{{ $url }}" target="_blank">Open Link in New Tab</a>
Now, when you visit the route associated with the openLinkInNewTab controller function, clicking on the “Open Link in New Tab” anchor tag will open the specified URL in a new browser tab.
Make sure you have defined the necessary routes and associated them with the controller function in your Laravel application.
[…] https://www.devopsconsulting.in/blog/open-link-in-new-tab-using-controller-function-in-laravel/ […]