I have a PayrollController which contains paySlipList() function. In paySlipList() I get $salary_year and $salary_month through $request object. I have made $payroll_lists variable which contains some model logic and I pass it to a view page for displaying employee info. My question is, how I can pass the $payroll_lists variable to more than one view. I google it and found the solution with View Composer but in compose() method of View Composer I am unable to call Request class. My $salary_year and $salary_month is received from my view page so it is necessary to receive it in compose() method or how to call compose() method from blade view. Please tell me some solution of this. Below is my controller function.
public function paySlipList(Request $request)
{
$payroll_lists = collect();
$salary_year = null;
$salary_month = null;
$salary_year = $request->get('salary_year');
$salary_month = $request->get('salary_month');
$payroll_lists = Payroll::where('gross_salary', '!=', 'null')
->where('salary_year', $salary_year)
->where('salary_month', $salary_month)
->where('is_payroll', '=', '1')
->where('net_salary', '<>', '0')
->with('employee')
->get();
if(count($payroll_lists) == 0)
{
return redirect()->route('payroll.payslip.index')
->with("error", 'No payroll generated for selected year or month!');
}
return view('backend.payroll.payslip_list',
compact('payroll_lists','salary_year','salary_month'));
}
Here is blade view,
<form action="{{ URL::route('payroll.payslip.sendPaySlipMail') }}" method="post">
@csrf
<input type="hidden" name="salary_year" value="{{$salary_year}}">
<input type="hidden" name="salary_month" value="{{$salary_month}}">
<div class="box-header">
<div class="box-tools pull-right">
<button type="submit">Send Payslips to Emails</button>
</div>
</div>
</form>
Any help would be appreciable!
compact... check the docs for thecompactfunction .. i would suggest not using it until you know what it does and the pitfalls of it (like silently not including missing table symbols before PHP v 7.3.0) ... also describe what you are actually trying to do, what your are describing you want to do is like an XY problem most likely