php - Laravel: Check if variable is being passed from controller


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>


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']))





pass the variable directly

@if (!$client_projects)




@if ($client_projects->count())



more info

People are also looking for solutions to the problem: Build a new list from existing with javascript or php


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.