从Laravel中的Button或URL运行功能 [英] Run function from Button or URL in Laravel

查看:201
本文介绍了从Laravel中的Button或URL运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 :)";
}

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

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

推荐答案

这是解决方案:

我们假定您在YourController中具有函数callMeDirectlyFromUrl,在这里您可以直接从URL,超链接或按钮调用该函数.

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.

创建路线

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

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

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

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

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

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

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

这篇关于从Laravel中的Button或URL运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆