Home > Software engineering >  cascaded isset with different if's don't work
cascaded isset with different if's don't work

Time:08-11

How do you set up multiple issets in cascade in a view?

<div >
    <div >
        @if (@isset($client_name))
        <h1>List of the overall tasks of the{{$client_name}}</h1> 
        @if (@isset($project_name_tasks))
        <h1>List of project tasks of {{$project_name_tasks}} </h1>
        @else
        <h1>List of project tasks</h1>
        @endif
        @endisset
    </div>
</div>

It does not work properly.

Can someone help me?

CodePudding user response:

You should use:

@isset($client_name)
    <h1>List of the overall tasks of the{{$client_name}}</h1> 
    @isset($project_name_tasks)
        <h1>List of project tasks of {{$project_name_tasks}} </h1>
    @else
        <h1>List of project tasks</h1>
    @endisset
@endisset

because@isset is Blade directive, so no need to have extra @if.

Alternatively you can of course use isset function from PHP but then you don't need to prefix it with @ so it should look like:

@if(isset($client_name))
    <h1>List of the overall tasks of the{{$client_name}}</h1> 
    @if(isset($project_name_tasks))
        <h1>List of project tasks of {{$project_name_tasks}} </h1>
    @else
        <h1>List of project tasks</h1>
    @endif
@endif

--EDIT--

If each isset is separate from each other you should just close condition earlier so:

@isset($client_name)
    <h1>List of the overall tasks of the{{$client_name}}</h1> 
@endisset
@isset($project_name_tasks)
   <h1>List of project tasks of {{$project_name_tasks}} </h1>
@else
  <h1>List of project tasks</h1>
@endisset

@endisset

  • Related