[英]How to add validate data search
我在這個項目中使用 laravel,我是 laravel 的新手然后我想添加驗證數據,如果有的話 go 到 pdf 刀片,除非數據是假的或錯誤的(我不知道它叫什么所以我將其命名為 True 和 False,但我希望你明白我的意思)
controller中有代碼方法搜索pdf
$id = $request->id;
$date = $request->date;
$pegawai = DB::table('pegawais')
->where('id', $id)
->whereDate('date', $date)
->get();
$pdf = PDF::loadview('pegawai_pdf', [
'pegawai'=>$pegawai
]);
return $pdf->stream();
這是 output 刀片,當我搜索數據是真實的或存在於此處時
這是我搜索時的 output 刀片,但數據為假或未找到數據存在
僅供參考,數據是來自播種機的虛假數據,
根據您的示例,我假設您想檢查 $pegawai 中是否有結果,對嗎? 那就數吧。
if (count($pegawai) > 0) {
// show your pdf output here
} else {
// there is no data, do something here
}
檢查這不需要是一個真正的錯誤變量你可以這樣檢查
if($pegawai){
$pdf = PDF::loadview('pegawai_pdf', [
'pegawai'=>$pegawai
]);
return $pdf->stream();
}else{
//show error here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.