Laravel 5.5从带有参数的刀片视图中调用Controller函数 [英] Laravel 5.5 call Controller function from blade view with parameter
本文介绍了Laravel 5.5从带有参数的刀片视图中调用Controller函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个产品滑块,我正在尝试找到每种产品的最低价格.
I have a slider of products and i'm trying to find the lowest price of each product.
因此,我首先要尝试从Controller成功调用函数并传递产品的id
并打印出来.
So i'm trying, first of all, to successfully call a function from a Controller and pass the id
of the product and also print it out.
blade.php
<span class="text-bold">
@php
use App\Http\Controllers\ServiceProvider;
echo ServiceProvider::getLowestPrice($product_cat->id);
@endphp
</span>
路线
Route::post('/getLowestPrice/{id}', 'ServiceProvider@getLowestPrice');
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ServiceProvider extends Controller
{
public static function getLowestPrice($id) {
return $id;
}
}
我得到一个错误
Parse error: syntax error, unexpected 'use' (T_USE)
您知道为什么use
在这里不起作用吗?
Any idea why use
is not working here?
推荐答案
您不能在方法内使用use
关键字
you can't use use
keyword inside method
您可以像这样编写完整的类路径
you can write the full class path , like this
<span class="text-bold">
@php
echo App\Http\Controllers\ServiceProvider::getLowestPrice($product_cat->id);
@endphp
</span>
这篇关于Laravel 5.5从带有参数的刀片视图中调用Controller函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文