2016-04-25 179 views
0

这是我询问的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', 

     ]; 
    } 
} 
+0

这是必须的'Requests \ CreateItem'这是失败。你能在那里向我们展示一些相关的代码吗? – user3158900

回答

0

所有我认为你应该删除此行的第一:如果你想在航线somethink改变

Route::post('/item/create', ['as' => 'item.store', 'uses' => '[email protected]']);

(名或控制器的方法)你应该此行之前放置:

Route::resource('item', 'ItemController');

你狂胜为了顺序是错误的,那就是为什么你已经回到了表单。

0

我想我可能已经找到了我的答案。 'filename', 'required|min:7',应该是filename => 'required|min:7'