当用户在打开页面之前以模态形式输入密码时,我现在正在使用Laravel保护页面。我初始化了一个名为$crypt
的变量,该变量隐藏在表单中,以使每个页面都是唯一的(以防止其他人使用URL打开页面)。
我想将$crypt
数据传递给PDFView。我怎样才能做到这一点?我已经尝试了很多东西,但是都没用。
错误
未定义变量:地穴
路线:
Route::get('/pdfview/{id}/', 'HomeController@pdfview')->name('pdfview');
生成的密钥代码
<div style="display: none">{{ $crypt = str_random(10)}}
控制器
public function encryptslip(Request $request, $crypt)
{
$crypts = $crypt;
$id = $request->nip;
$pass = $request->password;
$nip = Auth::user()->nip;
if (Hash::check($pass, Auth::user()->password)) {
return redirect('/pdfview/' . $nip . '/', ['crypts' => $crypts])->with('crypt', $crypt);
} else {
return redirect('/home')->with('alert', 'Incorrect password');
}
}
public function pdfview(Request $request, $id)
{
$route = url()->current();
$month = Carbon::now()->month;
$periodeinput = DB::table('payrollinput')->where('nip', '=', $id)->orderBy('periode', 'desc')->pluck('periode')->implode('periode');
$periodehistory = DB::table('payrollhistory')->where('nip', '=', $id)->orderBy('periode', 'desc')->pluck('periode')->implode('periode');
// if ($periodeinput !== $month && $periodehistory !== $month) {
// return redirect('home')->with('alert', 'Slip gaji anda siap.');
// } else {
if (Auth::user()->nip == $id) {
$employees = MasterEmployee::where('nip', '=', $id)->first();
$payrollhistory = MasterPayrollHistory::where('nip', '=', $id)->where('periode', '=', $month)->first();
$payrollinput = MasterPayrollInput::where('nip', '=', $id)->where('periode', '=', $month)->first();
view()->share('employees', $employees);
view()->share('payrollhistory', $payrollhistory);
view()->share('payrollinput', $payrollinput);
view()->share('id', $id);
// calculation code
return view('pdfview', ['id' => $id])->with('id', $id)
->with('earningtotal', $earningtotal)
->with('deductiontotal', $deductiontotal)
->with('takehomepay', $takehomepay)
->with('total', $total);
} else {
return redirect('home')->with('alert', 'Sorry it is personally confidential, you are not able to see it.');
}
}
查看
<div><{{$crypts}}</div>
答案 0 :(得分:1)
当您使用return redirect()
方法时,该变量将作为session
变量传递到视图,并且在blade
中,它必须称为form
<div>{{session('crypts')}}</div>
在session
上转换此$request
变量
{{Form:hidden('crypts', json_encode(session('crypts'))}}