php - Laravel: Check if variable is being passed from controller
673
I'm trying to check if variable is being passed from controller but isn't working, the controller function looks like here:
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]);
}
In the client blade I show the projects of each one with this code:
<h3 >Proyectos de {{$client->name}}</h3>
@foreach ($client_projects as $project)
<div >
<h4 ><a href="/admin/project/{{$project->id}}/edit" >{{$project->title}}</a></h4>
<a href="/admin/project/{{$project->id}}/edit"><img src="{{ asset('/storage/projects/'.$project->slug.'/header.jpg') }}" ></a>
</div>
@endforeach
But I only want to show it when have projects if not i don't want to show de .
I'm trying to do it with this code:
@if ( !empty($client_projects['slug']))
//code
@endif
Answer
Solution:
pass the variable directly
or
more info