0

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 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

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
Lluís Puig Ferrer
  • 1,128
  • 7
  • 19
  • 49

1 Answers1

1

pass the variable directly

@if (!$client_projects)

//code

@endif

or

@if ($client_projects->count())

//code

@endif

more info

Maraboc
  • 10,550
  • 3
  • 37
  • 48
madalinivascu
  • 32,064
  • 4
  • 39
  • 55