Laravel: How to implement if statement within {{ }}

  laravel, php

I’m having to pass search filters in links in my laravel app on various occasions. The following statement was working fine in laravel 4, but now I’m converting it to laravel 8 and its giving me error now.

{{ link_to_route('workprocess.edit', 'Edit Work Process', array($workprocess->id, json_encode($searchFilters)), array('class' => 'btn btn-sm btn-warning')) }}

Error

Missing required parameters for [Route: workprocess.edit] [URI: workprocess/edit/{workprocess}/{search?}]. (View: D:xampphtdocscompliance.localresourcesviewshome.blade.php)

Reason
$searchFilters is empty sometimes. $searchFilters = array('fromdate' => '', 'todate' => '', 'name' => '', 'type' => '');

I want to put an if statement inside {{ }} for json_encode($searchFilters) so that I don’t have to write code for two links as there are quite a few other such occurances.

Source: Laravel

Leave a Reply