2016-04-24 17 views
0

Hallo an alle, heute möchte ich eine Laravel-Anwendung erstellen, die eine E-Commerce-Website ist. Ich lerne gerade über das Hochladen von Dateien dieses Framework verwenden, die in diesem Fehler führt am Ende, wenn ich das Hochladen etwas versuchen:laravel - Hochladen von Dateien

> 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 

ich an den laracast Videos auf dieser Website haben gesucht und eine veraltete Video-on-Datei-Uploads gefunden. Ich bin ein wenig neu auf dem Laravel Rahmen und ich hoffe, ich Hilfe beim Hochladen bekommen und Validieren von Dateien

Hier ist, was meine routes.php Datei wie

 /* 
    |-------------------------------------------------------------------------- 
    | 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'); 
       } 

      } 

     } 

Mein Formular Code

@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 
+0

senden Sie eine POST zu 'ItemController @ Store'? Bitte posten Sie bitte den Controller, in dem Sie die 'store' Methode aufrufen. Wenn es von einem Formular kommt, geben Sie den Code Ihres Formulars ein – odannyc

Antwort

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

//Form

ersetzen

{!! Form::open() !!}

mit

{!! Form::open(['route' => 'item.store', 'files' => true]) !!}`

+0

Das löste den Fehler. Vielen Dank! –