【发布时间】:2018-04-25 21:27:22
【问题描述】:
我正在尝试检查变量是否从控制器传递但不起作用,控制器函数如下所示:
public function editClient($id)
{
$client = Client::find($id);
// $client_project = DB::table('client_project')->where('client_id',$id)->first()->project_id;
//$project = DB::table('projects')->where('id',$client_project)->first();
$client_projects = Client::find($id)->projects;
return view('cms.public.views.clients.editclient', ['client' => $client, 'client_projects' => $client_projects]);
}
在客户端刀片中,我使用以下代码显示每个项目的项目:
<h3 class="h3client h3clienteedit">Proyectos de {{$client->name}}</h3>
@foreach ($client_projects as $project)
<div class="col-md-3 col3projectofclient">
<h4 class="h4traductiontitle"><a href="/admin/project/{{$project->id}}/edit" class="atraductiontitle">{{$project->title}}</a></h4>
<a href="/admin/project/{{$project->id}}/edit"><img src="{{ asset('/storage/projects/'.$project->slug.'/header.jpg') }}" class="imgprojectoneditclient"></a>
</div>
@endforeach
但我只想在有项目时显示它,如果没有我不想显示 de。
我正在尝试使用此代码:
@if ( !empty($client_projects['slug']))
//code
@endif
【问题讨论】:
-
试试:
@if(!$client_projects) -
不工作@Hirengohel
-
好的,下面的答案对你有用!
-
您不需要第二次查询。