vendredi 30 septembre 2016

ReflectionException in Container.php line 741: Class App\Http\Controllers\Backend/ItemsController does not exist

i constantly get this error after i created the update/edit function, route and layout. After some research i tried:

namespace App\Http\Controllers\Backend\ItemsController; 

but still nothing.

Controller:

<?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Models\Item;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Laracasts\Flash\Flash;



class ItemsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $items = Item::orderBy('id', 'ASC')->paginate(5);

        return view('backend.item.list')->with("items", $items);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('backend.item.form');
    }


    public function store(Request $request)
    {
        // mejora:
        // $item = new Item($request->all());
        $item = new Item;
        $item->name = $request->get('name');
        $item->pompadour = $request->get('pompadour');
        $item->description = $request->get('description');
        $item->outstanding_image = '';
        $item->save();

        Flash::success("Se ha agregado un nuevo item " . $item->name . " con exito");

        return redirect()->route('item.index');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $item = Item::find($id);

        //return view('items.show')->withItem->($item);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
         $item = Item::find($id);
         return view('items.edit')->with('item', $item);
    }

    public function destroy($id)
    {
        // delete
        $item = Item::find($id);
        $item->delete();

        Flash::error("El item " . $item->name . " ha sido eliminado correctamente");

        return redirect()->route('item.index');
    }

    public function update(Request $request, $id)
    {
        $item = Item::find($id);
        $item->name = $request->name;
        $item->pompadour = $request->pompadour;
        $item->description = $request->description;
        $item->save();

        Flash::info("El item " . $item->name . " ha sido editado correctamente");

        return redirect()->route('item.index');

    }
}

Routes ( this are the only one that do not work, i also have the destroy route, store and create):

Route::get('item/{id}/edit', ['as' => 'items.edit', 'uses' => 'Backend/ItemsController@edit']);
Route::put('item/{id}', ['as' => 'items.update', 'uses' => 'Backend/ItemsController@update']);

While my form action look like:

<form action="" method="PUT" class="form-horizontal">

Thanks for taking the time reviewing my code.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire