Привет всем сегодня, я пытаюсь создать приложение 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', 'ItemController@Store'); Route::auth(); Route::get('/home', 'HomeController@index'); 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