Laravel 5.5 - 将表单的数据传递给控制器,然后将数据从控制器传递到同一个视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48487800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.5 - Passing form's Data to Controller then Passing Data from Controller to the same View
提问by Kamil Lonowski
I give up ! 2days i'm looking for solution for my problem. All I need is pass FORM Data to Controller, then just show it on the same View. Easy, right ? But i can not find any solution and Laravel's Manual does not explain that clearly...
我放弃 !2 天我正在为我的问题寻找解决方案。我所需要的只是将 FORM 数据传递给控制器,然后将其显示在同一个视图上。很简单,对吧?但是我找不到任何解决方案,而且 Laravel 的手册没有清楚地解释...
So this is my View with the form :
所以这是我的表单视图:
form.blade.php
form.blade.php
<form action="{{ action('FormController@ReceiveDataForm') }}" method="post">
<input type="text" name="name" placeholder="Enter your name">
<input type="text" name="surname" placeholder="Enter your surname">
<input type="submit" value="Send">
</form>
<div class="ShowDataHere">
{{-- Here i want to show this Data from FORM above, but with using Controller. --}}
</div >
My Controller receiving data:
我的控制器接收数据:
FormController.php
表单控制器.php
namespace App\Http\Controllers;
use Input;
use Illuminate\Http\Request;
class FormController extends Controller
public function Form()
{
return view('test.form');
}
public function ReceiveDataForm()
{
Input::post('name');
Input::post('surname');
}
And my question is how to pass this Data to the same View and show it on
user's screen ?
Please note that Data must be basically pushed to the Controller, just then passing to the View via Routing.
All solution i found in Internet does not work for me, what guys am i doing wrong ?
我的问题是如何将此数据传递给同一个视图并将其显示在用户屏幕上?请注意,Data 必须基本上推送到 Controller,然后通过 Routing 传递到 View。
我在互联网上找到的所有解决方案都对我不起作用,我做错了什么?
If you do not know proper answer, please direct me where to find it or similar.
如果您不知道正确的答案,请告诉我在哪里可以找到它或类似的答案。
Thank You !
谢谢你 !
采纳答案by Prince Lionel N'zi
You can do
你可以做
public function ReceiveDataForm(Request $request)
{
//Input::post('name');
//Input::post('surname');
return view('test.form');
}
Import the Request
class by adding use Illuminate\Http\Request;
in your controller.
In your view
Request
通过添加use Illuminate\Http\Request;
控制器来导入类。在你看来
<div class="ShowDataHere">
@if(!empty(request()->all()))
{{ request()->name }}
@endif
</div >
In your web.php file, make sure you have
在你的 web.php 文件中,确保你有
Route::post('/test', 'FormController@ReceiveDataForm');