从 Laravel 中的 Button 或 URL 运行函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27322854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:49:16  来源:igfitidea点击:

Run function from Button or URL in Laravel

laravellaravel-5laravel-5.1laravel-5.2laravel-4.2

提问by maytham-???????

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

我有以下测试功能,我想直接从我的 URL 或通过单击我的刀片视图中的链接来调用它。

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?

我的问题:是否可以直接从 Laravel 中的刀片视图中的按钮单击或 URL 链接调用函数?

回答by maytham-???????

Here is the solution:

这是解决方案:

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

我们假设你有一个函数callMeDirectlyFromUrlYourController,这里怎么可以从网址,超链接或按钮直接调用该函数。

Create Route

创建路线

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

Add link in the view blade php file

在视图刀片 php 文件中添加链接

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

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

到目前为止,这已经在 Laravel 4.2 -> 5.2 上进行了测试。

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

通过单击此链接或调用 URL,www.somedomain.com/pagelink该函数将直接执行。