在各种情况下,我必须在laravel应用程序的链接中传递搜索过滤器。以下语句在laravel 4中工作正常,但现在我将其转换为laravel 8,现在给了我错误。
@GetMapping(value = "/batchpolling/{waybill}/{cp_id}", headers="Accept=application/json", produces="application/json")
public ResponseEntity<Map<String, BatchPollingResponse>> getBatchPollingResponse( @PathVariable("waybill") String waybill) throws JsonProcessingException {
BatchPollingResponse batchPollResponse = null;
try {
----------------------
batchPollResponse = restTemplate.getForObject(url, BatchPollingResponse.class);
----------------------
}catch(Exception e) {
LOGGER.error("Error processing OrderCreationMPS - getBatchPollingResponse");
e.printStackTrace();
}
return ResponseEntity.ok(Map.of(waybill, batchPollResponse));
}
错误
{{ link_to_route('workprocess.edit', 'Edit Work Process', array($workprocess->id, json_encode($searchFilters)), array('class' => 'btn btn-sm btn-warning')) }}
原因
$ searchFilters为空有时是因为相同的模板也用于搜索。 Missing required parameters for [Route: workprocess.edit] [URI: workprocess/edit/{workprocess}/{search?}]. (View: D:\xampp\htdocs\compliance.local\resources\views\home.blade.php)
我想在$searchFilters = array('fromdate' => '', 'todate' => '', 'name' => '', 'type' => '');
的{{}}内放置一个if语句,这样我就不必为两个链接编写代码,因为还有很多其他这样的情况。
答案 0 :(得分:0)
这将是我的解决方案;
设置了$ searchFilters的位置
$output.= sprintf ("%d<br>",$roomsCount[$i]);
并在if (empty($searchfilters)) {
$searchfilters = 1;
};
方法内添加三元数:
json_encode
答案 1 :(得分:0)
您可以使用简写形式添加if语句:
{{ $var === "hello" ? "Hi" : "Goodbye" }}