Skip to content
Advertisement

Passing values to blade using redirect() and back() functions

I have successfully pass values from form to controller. Calculation is is working well, since its dump all the values using dd($fee); dd($vat); dd($Transaction_vat);.

But now, when I try to pass the values to blade using return redirect()->back()->with('fee', $fee ,'vat', $vat , 'Transaction_vat', $Transaction_vat); , only fee is captured $fee and the rest of the data is ommitted. This is how I capture data in blade;

<table class="table">
    <thead>
        <th>vat</th>
        <th>vpaysa fee</th>
        <th>Total</th>
    </thead>
    <tbody>
        <td>{{ session('vat') }}</td>
        <td>{{ session('fee') }}</td>
        <td> {{ session('Transaction_vat') }}</td>
    </tbody>
</table>

This is how controller looks like

public function feeCal(Request $request)
    {
        $value = $request->input('price');
        $vat = 115;


        if ($value > 0 or $value > 10000) {
            $fee = ($value * 0.0115);
            
            $Transaction_vat = $vat + $fee;
        }
        elseif ($value > 10001 or $value > 100000) {
            $fee = ($value * 0.01);
            
            $Transaction_vat = $vat + $fee;
        }
        elseif ($value > 100001 or $value > 500000) {
            $fee = ($value * 0.0085);
            
            $Transaction_vat = $vat + $fee;
        }
        elseif ($value > 500001 or $value > 1000000) {
            $fee = ($value * 0.0065);
            
            $Transaction_vat = $vat + $fee;
        }
        elseif ($value > 1000001 or $value > 5000000) {
            $fee = ($value * 0.0045);
            
            $Transaction_vat = $vat + $fee;
        }
        elseif ($value > 5000001 or $value > 10000000) {
            $fee = ($value * 0.0035);
            
            $Transaction_vat = $vat + $fee;
        }
        elseif ($value > 10000000) {
            $fee = ($value * 0.0025);
        
            $Transaction_vat = $vat + $fee;
        }

        dd($fee);
        dd($vat);
        dd($Transaction_vat);
        return redirect()->back()->with('fee', $fee ,'vat', $vat , 'Transaction_vat', $Transaction_vat);
    }


Now my question is, How do I pass all the values in ->with('fee', $fee ,'vat', $vat , 'Transaction_vat', $Transaction_vat) to blade?

Advertisement

Answer

You have 2 possibilities.

1 – Try something like :

return redirect()->back()->with('fee', $fee)
        ->with('vat', $vat)
        ->with('Transaction_vat', $Transaction_vat);

2 – Or like :

return redirect()->back()->with([
       'fee' => $fee, 
       'vat' => $vat, 
       'Transaction_vat' => $Transaction_vat
]); 
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement