Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php laravel 5.3 passing an input value from one blade file to another blade file

I want to pass an input value from one blade file to another blade file.

I'm new to PHP Laravel, and I'm getting an error when attempting to use it.

I think my syntax is wrong here. Can somebody help?

channeling.blade:

<select class="form-control " name="fee" id ="fee"></select>

This is the link to the next page, where i want to send the value of "fee":

<input type="hidden" value="fee" name="fee" />
<a href="{{ url('pay ') }}">Click to Channel</a></p>

This is my web.php:

Route::post('pay', [
    'as' => 'fee',
    'uses' => 'channelController@displayForm'
]);

This my controller class:

 public function displayForm()
    {
        $input = Input::get();
        $fee = $input['fee'];
        return view('pay', ['fee' => $fee]);
    }

Error message:

Undefined variable: fee 
(View: C:\xampp\htdocs\lara_test\resources\views\pay.blade.php)

pay.blade:

<h4>Your Channeling Fee Rs:"{{$fee}}"</h4>
like image 340
sara99 Avatar asked Nov 08 '22 04:11

sara99


1 Answers

You should use form to send post request, since a href will send get. So, remove the link and use form. If you use Laravel Collective, you can do this:

{!! Form::open(['url' => 'pay']) !!}
{!! Form::hidden('fee', 'fee') !!}
{!! Form::submit() !!}
{!! Form::close() !!}

You can value inside a controller or a view with request()->fee.

Or you can do this:

public function displayForm(Request $request)
{
     return view('pay', ['fee' => $request->fee]);
}
like image 77
Alexey Mezenin Avatar answered Nov 14 '22 23:11

Alexey Mezenin