Run function from Button or URL in Laravel

30,719

Here is the solution:

We assume you have a function callMeDirectlyFromUrl in YourController, here how you can call the function directly from URL, Hyperlink or Button.

Create Route

Route::get('/pagelink', 'YourController@callMeDirectlyFromUrl');

Add link in the view blade php file

<a href="{{action('YourController@callMeDirectlyFromUrl')}}">Link name/Embedded Button</a>

This has been tested on Laravel 4.2 -> 5.2 so far.

By clicking on this link or call the URL www.somedomain.com/pagelink the function will executed directly.

Share:
30,719
Maytham Fahmi
Author by

Maytham Fahmi

Maytham is a passionate software developer with more than ten years of experience. His motivation is to help clients transform ideas into production ready systems. This includes ownership of all processes and of leading and engaging other people, if necessary, to achieve the goal. His primary focus is backend development using .NET / C#, Azure Developer (Certified AZ-204) and Azure DevOps Developer. For the past 5 years, Maytham has delivered successful client projects based on the Microsoft .NET stack to corporate clients in the areas of finance, banking, insurance, and telecommunications. He has experience working in several modern project management methods such as Scrum, Agile and Kanban. Maytham is not afraid to take responsibility and ownership. He has a penchant for leadership and mastering communication at all levels of the business from end users, developers, operations to CxO level. Maytham believes that the most important aspects of successful projects are team players, openness, and clear communication. He emphasizes documentation as part of the delivery, as this helps ensure transparency and facilitate that maintenance. I enjoy working with software development, not only because it’s my livelihood, but it’s also my hobby. When you encounter people with positive attitudes and experience in the field, this always translates into a positive influence on both technological and personal development. With very best regards, maytham-ɯɐɥʇʎɐɯ Software Engineer maythamfahmi @ itbackyard.com Blog: https://itbackyard.com LinkedIn: https://www.linkedin.com/in/maythamfahmi Github: https://github.com/maythamfahmi My first Microsoft Visual Studio Professional .net Version 2002 My first Computer 1985

Updated on July 09, 2022

Comments

  • Maytham Fahmi
    Maytham Fahmi almost 2 years

    I have the following test function, that I want to call directly from my URL or by clicking a link from my blade view.

    public function callMeDirectlyFromUrl()
    {
        return "I have been called from URL :)";
    }
    

    My Question: Is it possible to call a function directly from button-click or URL link from blade view in Laravel?