title: How can i use php conditions inside json data?
body: <p>Below is the code inside my CategoryResource.php</p>
  <pre><code>        [
              'id' =&gt; $this-&gt;id,
              'name' =&gt; $this-&gt;name,
              'categories' =&gt; CategoryResource::collection($this-&gt;children),
              'items' =&gt; ItemListResource::collection($this-&gt;items)
          ];
  </code></pre>
  <p>and by this i am getting response like:<br/></p>
  <pre><code>{
    &quot;status&quot;: true,
    &quot;data&quot;: {
      &quot;categories&quot;: [
        {
          &quot;id&quot;: 10,
          &quot;name&quot;: &quot;Fast Food&quot;,
          &quot;categories&quot;: [
            {
              &quot;id&quot;: 11,
              &quot;name&quot;: &quot;Pizza&quot;,
              &quot;categories&quot;: [],
              &quot;items&quot;: [
                {
                  &quot;id&quot;: 9,
                  &quot;name&quot;: &quot;Ham \u0026 Crab Stick&quot;,
                  &quot;price&quot;: &quot;20.00&quot;,
                  &quot;image&quot;: &quot;up/products/c11/Mrn4OpjngYRCkRJ28rJ1LbXUOXy0XjTRyXU7eFoi.jpg&quot;
                }
              ]
            }
          ],
          &quot;items&quot;: []
        }
      ]
    }
  }
  </code></pre>
  <p>i dont want <code>&quot;categories&quot; : []</code> when category does not exist for a category.
  please suggest some ideas or ways i can deal with this issue.</p>