Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Open link in new tab using Controller function in laravel

Laravel

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
1
0
Would love your thoughts, please comment.x
()
x