這是我詢問的previous問題的後續問題。我按照指示添加了代碼,但現在當我的表單觸及上傳字段時,我只是將bacl重定向到表單。laravel - 文件沒有上傳到上傳文件夾
這是我的觀點:
@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', '[email protected]');
Route::post('/item/create', ['as' => 'item.store', 'uses' => '[email protected]']);
Route::get('/item', '[email protected]');
//Route
有什麼建議? 編輯:這裏是我的要求\ CreateItem.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',
];
}
}
這是必須的'Requests \ CreateItem'這是失敗。你能在那裏向我們展示一些相關的代碼嗎? – user3158900