Php Laravel如何在控制器中使用if stament
我有两个函数(Php Laravel如何在控制器中使用if stament,php,laravel,if-statement,controller,Php,Laravel,If Statement,Controller,我有两个函数(index和dateRange) 在index.blade.php中,我想使用if语句来选择它将运行的函数 但当我打字时: index{ if($request['from'] != null ) { //run this} 但是这次,indexController没有运行 request()->ajax() this if statement }.. 我怎么办 以下是我的全部功能: public function index(Request $request) {
index
和dateRange
)
在index.blade.php
中,我想使用if语句来选择它将运行的函数
但当我打字时:
index{ if($request['from'] != null ) { //run this}
但是这次,indexController
没有运行
request()->ajax() this if statement }..
我怎么办
以下是我的全部功能:
public function index(Request $request)
{
if (!Gate::allows('follow_access')) {
return abort(401);
}
if (request()->ajax()) {
$query = Follow::query()->where('qr_approved', 1)->where('qr_non_approved', 0);
$query->with("competitor_product");
$query->with("product");
$query->with("user");
$template = 'actionsTemplate';
if ($request['From'] != null || $request['To'] != null) {
dd("try me");
}
if (request()->ajax()) {
// NOT WORK
}
}
}
这里更新了下面的代码
public function index(Request $request)
{
if (!Gate::allows('follow_access')) {
return abort(401);
}
if ($request->ajax()) {
$query = Follow::query()->where('qr_approved', 1)->where('qr_non_approved', 0);
$query->with("competitor_product");
$query->with("product");
$query->with("user");
$template = 'actionsTemplate';
if ($request['From'] != null || $request['To'] != null) {
dd("try me");
}
if ($request->ajax()) {
// NOT WORK
}
}
}
发布你的控制器代码完成blade
如果
s是@if()…@endif
请不要在评论中发布代码,编辑你的问题并粘贴到那里。ThxI已将request()-.>ajax()更改为$request->ajax()