0
大家好,今天我正在尝试构建一个电子商务网站的Laravel应用程序。我只是学习有关文件上传使用这一框架内,最终导致这个错误时,我尝试上传的东西:laravel - 上传文件
> MethodNotAllowedHttpException in RouteCollection.php line 219:
in RouteCollection.php line 219
at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php line 206
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 823
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
我看了那个网站上的laracast视频和发现文件上传一个过时的视频。我有些新来的Laravel框架,我希望我得到一些帮助,上传和验证文件
这里就是我的routes.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.
|
*/
Route::resource('item', 'ItemController');
Route::get('welcome', function() {
return view('welcome');
});
Route::post('item', '[email protected]');
Route::auth();
Route::get('/home', '[email protected]');
EDIT my item controller
<?php
namespace App\Http\Controllers;
use Request;
use App\Http\Requests;
use App\Item;
class ItemController extends Controller
{
public function index()
{
//fetch all items from the database
$items = Item::All();
return $items;
}
public function show($id)
{
$item = Item::find($id);
if (is_null($item)) {
abort(404);
}
return view('item.show', compact('item'));
}
/**
* @return mixed
*/
public function create()
{
return view('item.create');
}
public function store(Requests\CreateItem $request)
{
Item::create($request->all());
if($request->hasFile('filename')) {
$file = $request->file('filename');
if($request->file('photo')->isValid()) {
$request->file('filename')->move('/uploads');
}
}
}
我的表单代码
@extends('app');
@section('content');
<h1>Add a new item</h1>
<hr />
<content>
<div class="form-group">
{!! Form::open() !!}
{!! 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
你发送POST到'ItemController @ Store'?请张贴您要调用'store'方法的控制器。如果它来自表单,请发布表单的代码 – odannyc