2017-04-17 90 views
1

我在Laravel 5.4背包管理员中添加新闻的简单形式只是为了获得Laravel 5.4的概述,但是在发布来自位于新闻/添加视图。虽然我正在向添加方法的新闻控制器发送操作,但它显示了405方法不允许的错误。请检查我的代码,并让我知道它有什么问题。可能是我在做一些愚蠢的错误,对不起,如果是这样的话。405方法不允许错误来自Laravel 5.4背包中的表单发布数据Admin

查看:add.blade.php

{!! Form::open(['action' => '[email protected]']) !!} 
<div class="form-group"> 
<label for="title">Title:</label> 
<input name="title" id="title" type="text" class="form-control" required> 
</div> 
<div class="form-group"> 
<label for="description">Description:</label> 
<textarea name="description" id="description" class="form-control"> 
</textarea> 
</div> 
<button class="btn btn-default" type="submit" name="submitBtn" 
value="Submit">Submit</button> 
{!! Form::close() !!} 

控制器:NewsController.php

public function add(){ 
echo "<pre>"; print_r($this->data->request); die; 
return view("news.add"); 
} 

<code>405 method not allowed error coming while posting data from form in Laravel 5.4 backpack Admin</code>

+0

请附上路线列表。 –

回答

1

首先,在顶部的控制器补充一点: -

use Illuminate\Http\Request; 
use App\Http\Requests; 

之后,你的功能应该有这个parmeter请求$要求: -

public function add(Request $request){ 
    $data = $request->all(); 
    return view("news.add"); 
} 

希望它能帮助!

0

好像在路由文件的方法是不POST

改变你的路线是这样的:

Route::post('/addnews',['as' => 'news.add', 'uses'=>'[email protected]']); 

我会建议你使用命名的路由。它会很容易使用。

{!! Form::open(['route' => 'news.add']) !!} 
0

使用此格式:

{!! Form::open(array('url' => 'add')) !!} 
    // your form fields 
{!! Form::close() !!} 

您的路线将是:

Route::post('/add','[email protected]'); 

希望它可以帮助..