Php laravel 5.3 transferring input value from one blade file to another blade file

I want to transfer the input value from one blade file to another click file.

I am new to PHP Laravel and I get an error when trying to use it.

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

channeling.blade:

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

This is a 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 class of my controller is:

  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> 
+5
source share
5 answers

I changed the code like this and it worked.

echanneling.blade

  <input type="hidden" value="fee" name="fee" /> <button type="submit" class="btn btn-submit">Submit</button> 

channelController.php

 public function about(Request $request) { $input = Input::get(); $fee = $input['fee']; return view('pay')->with('fee',$fee); } 

Web.php Route :: post ('/ pay', 'channelController @about');

0
source

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

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

You can evaluate inside the controller or view using request()->fee .

Or you can do this:

 public function displayForm(Request $request) { return view('pay', ['fee' => $request->fee]); } 
+1
source

I think you can try this, you are mistaken url('pay ') with a space:

change your code:

 <a href="{{ url('pay ') }}">Click to Channel</a></p> 

to

 <a href="{{ url('pay') }}">Click to Channel</a></p> 

In the future, your question requires more correction, so I think you need to look at it first.

You can see how to create a form with laravel 5.3 . Hope this helps you.

0
source

You must use the form to submit data, and then you must submit the form to the click event

  <form id="form" action="{{ url('pay') }}" method="POST" style="display: none;"> {{ csrf_field() }} <input type="hidden" value="fee" name="fee" /> </form> 

In the click <a> event

 <a href="{{ url('/pay') }}" onclick="event.preventDefault(); document.getElementById('form').submit();"> Logout </a> 
0
source

tl; dr: I believe that @AlexeyMezenin's answer is the best help so far.

Your current problems:

  • If you decide to use <a href="{{ url('pay') }}">Click to Channel</a> you should use Route::get(...) . Use Route::post(...) for requests submitted by forms.

  • An instance of Input created. Input::get() requires a form request to exist. Thus, the error message is $fee an Undefined .

  • The value <input type="hidden" value="fee" name="fee"/> will always be the string "board" . (Unless there is some kind of magic spell cast by some JavaScript code).

  • laravel docs show that you are typing the Request type when accessing HTTP requests so that the incoming request is automatically entered into your controller method. Now you can $request->fee . Amazing right?


The way forward:

  • BasicTaskList The Laravel 5.2 tutorial began my journey in Laravel.
0
source

Source: https://habr.com/ru/post/1262016/


All Articles