这是我上一个问题的后续问题。我按照说明添加了代码,但是现在当我的表单命中上传字段时,我得到的只是将 bacl 重定向到表单。
以下是我的观点:
@extends('app');
@section('content');
<h1>Add a new item</h1>
<hr />
<content>
<div class="form-group">
{!! Form::open(['route' => 'item.store', 'files' => true]) !!}
{!! Form::label('name', "Name") !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
{!! Form::label('filename', "File Name") !!}
{!! Form::file('filename', null, ['class' => 'form-control']) !!}
{!! Form::label('description', 'Description') !!}
{!! Form::textarea('description', null, ['class' => 'form-control']) !!}
{!! Form::submit('Add Item', ['class' => 'btn btn-primary form-control']) !!}
</content>
</div>
@stop
这是我的控制器
public function store(Requests'CreateItem $request)
{
Item::create($request->all());
// if (Input::hasFile('filename')) {
// $file = $request->file('filename');
// $file->move(public_path().'/uploads', $file->getClientOriginalName());
//
// echo "File Uploaded";
//
// }
dd(Input::all());
}
这是我的路线
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::resource('item', 'ItemController');
Route::get('/', function() {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController@index');
Route::post('/item/create', ['as' => 'item.store', 'uses' => 'ItemController@store']);
Route::get('/item', 'ItemController@store');
//Route
有什么建议吗?编辑:这是我的请求''创建项目.php文件
<?php
namespace App'Http'Requests;
use App'Http'Requests'Request;
class CreateItem extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true; // for now
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|min:3',
'filename', 'required|min:7',
];
}
}
首先,我认为您应该删除此行:
Route::post('/item/create', ['as' => 'item.store', 'uses' => 'ItemController@store']);
如果你想改变路由中的一些想法(名称或控制器方法),你应该把它放在这一行之前:
Route::resource('item', 'ItemController');
您的路线顺序错误,这就是您返回表单的原因。
我想
我可能已经找到了答案。 'filename', 'required|min:7',
应该filename => 'required|min:7'