简体   繁体   English

从视图内部的按钮调用控制器功能?

[英]Call controller function from button inside view?

I want to call a controller function when i click a button but the problem is when i enter the page where the button is the function that im testing runs without clicking the button and i dont know why. 我想在单击按钮时调用控制器功能,但是问题是当我进入按钮所在的页面时,该功能是即时测试运行而无需单击按钮的功能,我不知道为什么。

Here is my button. 这是我的按钮。

<button  href="{{action('PlantillaImagenesController@testboi')}}"  style="width:27%" class="p-2 btn btn-primary btn-lg">Guardar</button>

The function that im testing. 我正在测试的功能。

 public function testboi(){
        echo "Funcion controller";
    }

My route. 我的路线。

Route::get('/Imagen',  'PlantillaImagenesController@testboi');

Make this change to your button: 对按钮进行此更改:

<a href="{{ url('Imagen') }}" style="width:27%" class="p-2 btn btn-primary btn-lg">Guardar</a>

your button URL should match with the route name, this is how you call a route in laravel. 您的按钮网址应与路线名称匹配,这就是您在laravel中调用路线的方式。

You can also name your route like this: 您也可以这样命名您的路线:

Route::get('imagen', 'PlantillaImagenesController@testboi')->name('imagen');

And use it like this: 并像这样使用它:

<a href="{{ route('imagen') }}" style="width:27%" class="p-2 btn btn-primary btn-lg">Guardar</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM