Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel Post表单数据_Php_Laravel - Fatal编程技术网

Php Laravel Post表单数据

Php Laravel Post表单数据,php,laravel,Php,Laravel,我无法从我的laravel应用程序中的表单获取数据,并且无法在同一控制器中使用其他方法显示数据 这是我的FormController class ForumController extends Controller { + + private $name, + $description; + + public function __construct() { + $this->middleware('auth'); + } + + /** +

我无法从我的laravel应用程序中的表单获取数据,并且无法在同一控制器中使用其他方法显示数据

这是我的FormController

class ForumController extends Controller {
+
+   private $name,
+           $description;
+
+   public function __construct() {
+       $this->middleware('auth');
+   }
+
+   /**
+    * Show the form for creating a new resource.
+    *
+    * @return Response
+    */
+   public function create()
+   {
+       return view('forum.create');        
+
+       $this->name = Input::post('name');  
+   }
+
+   /**
+    * Show the details of their input once its created
+    */
+   public function created()
+   {   
+       var_dump($this->name);
+   }
+}
这是我的Routes.php

Route::get('/group/create', 'ForumController@create');
+Route::post('/group/create', 'ForumController@created');
这是我的论坛创建视图

@extends('app')
+
+@section('content')
+   
+   <div class="container">
+       <h1>Create a Forum</h1>
+       <hr>
+       
+       <div class="panel panel-default">
+           <div class="panel-heading">Create your own forum here!</div>
+           
+           <div class="panel-body">
+               @if (count($errors) > 0)
+                   <div class="alert alert-danger">
+                       <strong>Whoops!</strong>There were some problems with your input.<br><br>
+       <ul>
+           @foreach ($errors->all() as $error)
+               <li>{{ $error }}</li>
+           @endforeach
+       </ul>
+               @endif
+               <form class="form-horizontal" method="POST" action="{{ url('/group/create') }}">
+
+                   <input type="hidden" name="_token" value="{{ csrf_token() }}">  
+                   
+                   <div class="form-group">
+                       <label class="col-md-4 control-label">Name</label>
+                       <div class="col-md-6">
+                           <input type="text" class="form-control" name="name" min="1" max="20">
+                       </div>
+                   </div>
+
+                   <div class="form-group">
+                       <label class="col-md-4 control-label">Description</label>
+                       <div class="col-md-6">
+                           <input type="text" class="form-control" name="description" min="1" max="255">
+                       </div>
+                   </div>
+                   
+                   <div class="form-group">
+                       <div class="col-md-6 col-md-offset-4">
+                           <button type="submit" class="btn btn-primary">
+                               Create
+                           </button>
+                       </div>
+                   </div>
+               </form>
+           </div>
+       </div>  
+   </div>  
+@stop
@extends('app')
+
+@节(“内容”)
+   
+   
+创建论坛
+
+ + +在这里创建你自己的论坛! + + +@if(计数($errors)>0) + +哇您的输入有一些问题。

+
    +@foreach($errors->all()作为$error) +
  • {{$error}
  • +@endforeach +
+@endif + + + + + +名字 + + + + + + +描述 + + + + + + + + +创造 + + + + + + + +@停止

有人能给我指出正确的方向吗?

好吧,你的例子中的失败点是,当你加载
创建的
路由时,PHP不会持久化
$this->name
。事实上,正如评论员所说,
$this->name
从未被设置,因为在它的定义之前有一个return语句

在创建方法中设置
$this->name
后。当您导航到创建的路由时,
$this->name
不再设置,即使您要在设置name之后移动return语句

您需要将数据列在数据库/会话/缓存中,或者从create方法重定向到传递数据的created方法

public function create() 
{
    // Handle POST Here
    if (Input::has('name')) {
       $this->name = Input::get('name'); 

        // $this->name is redundant but even still...
        return Redirect::to('created', array('name' => $this->name));
    }

    return view('forum.create');        
}
或检查:

echo var_dump($_POST); 
您应该在要发布到的控制器方法中包含此代码。 如果您想保存某个请求,然后将其丢弃,则可以将这些值保存在会话或flashdata中。您需要将视图重定向到某个视图或路由


$this->从未设置名称。因为它是死代码,因为他已经在他的控制器方法中返回了。
echo var_dump($_POST);