0

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!

3
  • pass it to session Commented Jul 16, 2020 at 12:24
  • you are passing the wrong names to compact ... check the docs for the compact function .. 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 Commented Jul 16, 2020 at 16:26
  • I know how to use compact(), its a typing mistake while asking a question I have edited it and sorry for the mistake Commented Jul 20, 2020 at 5:32

1 Answer 1

1
$data = Users::find($id);

$view = [

           view('users.index', compact('data')),
            view('users.members', compact('data')),
            view('users.admin', compact('data')),
        ];

        return $view;
Sign up to request clarification or add additional context in comments.

3 Comments

While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
you can add multiple views .
I cant add multiple views like that as you suggested

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.