Best Cosmetic Hospitals Near You

Compare top cosmetic hospitals, aesthetic clinics & beauty treatments by city.

Trusted • Verified • Best-in-Class Care

Explore Best Hospitals

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.

Best Cardiac Hospitals Near You

Discover top heart hospitals, cardiology centers & cardiac care services by city.

Advanced Heart Care • Trusted Hospitals • Expert Teams

View Best Hospitals
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