laravel类POS \ Http \ Request \ CategoriaFormRequest不存在

时间:2017-04-11 06:17:45

标签: laravel frameworks laravel-5.4

我正在学习laravel,但是我可以解决这个错误,请帮忙。 (laravel版本5.4.17)

因此,有一个视图显示所有类别,它们是添加新类别的按钮。 (如图中所示)

main view for a list of categories

new categorie view

这是我的Controller(CategoriaController.php)

<?php
namespace POS\Http\Controller;
use Illuminate\Http\Request;
use POS\Categoria;
use Illuminate\Support\Facades\Redirect;
use POS\Http\Request\CategoriaFormRequest;
use DB;

class CategoriaController extends Controller
{
    public function __construct()
    {

    }
    public function index(Request $request){
        if($request){
            $query=trim($request->get('SearchText'));
            $categorias=DB::table('categoria')->where('nombre','LIKE','%'.$query.'%')
            ->where('condicion','=','1') //muestra las categorias con condicion activa
            // ->orderBy('idcategoria','desc') //ordena de manera descendente
            ->paginate(); //paginacion que muestra registros de 10 en 10
            return view('almacen.categoria.index',["categorias"=>$categorias,"searchText"=>$query]);
        }
    }
    public function create(){
        return view("almacen.categoria.create");
    }
    public function store(CategoriaFormRequest $request){
        $categoria=new Categoria;
        $categoria->nombre=$request->get('nombre');
        $categoria->descripcion=$request->get('descripcion');
        $categoria->condicion='1';
        $categoria->save();
        return Redirect::to('almacen/categoria');
    }
    public function show($id){
        return view("almacen.categoria.show",["categoria"=>Categoria::findorfail($id)]);
    }
    public function edit($id){
        return view("almacen.categoria.edit",["categoria"=>Categoria::findorfail($id)]);
    }
    public function update(CategoriaFormRequest $request,$id){
        $categoria=Categoria::findorfail($id);
        $categoria->nombre=$request->get('nombre');
        $categoria->descripcion=$request->get('descripcion');
        $categoria->update();
        return Redirect::to('almacen/categoria');
    }
    public function destroy($id){
        $categoria=Categoria::findorfail($id);
        $categoria->condicion='0';
        $categoria->update();
        return Redirect::to('almacen/categoria');
    }

}

?>

然后这是我的路线(web.php)

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::resource('almacen/categoria','CategoriaController');

这是我的请求(CategoriaFormRequest.php)

<?php

namespace POS\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CategoriaFormRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nombre'=>'required|max:50',
            'descripcion'=>'max:256',
        ];
    }
}

这也是我的观点(create.blade.php)

@extends ('layouts.admin')
@section ('contenido')
    <div class="row">
        <div class="col-lg-6 col-md-6 col sm-6 col-xs-12">
            <div class="page-header">Nueva Categoría</div>
            @if (count($errors)>0)
            <div class="alert alert-danger">
                <ul>
                @foreach ($errors->all() as $error)
                    <li>{{$error}}</li>
                @endforeach
                </ul>
            </div>
            @endif

            {!!Form::open(array('url'=>'almacen/categoria','method'=>'POST','autocomplete'=>'off'))!!}
            {{Form::token()}}
            <div class="form-group">
                <label for="nombre">Nombre</label>
                <input type="text" name="nombre" class="form-control" placeholder="Nombre...">
            </div>
            <div class="form-group">
                <label for="descripcion">Descripción</label>
                <input type="text" name="descripcion" class="form-control" placeholder="Descripción...">
            </div>
            <div class="form-group">
                <button class="btn btn-primary" type="submit">Guardar</button>
                <button class="btn btn-danger" type="reset">Cancelar</button>
            </div>

            {!!Form::close()!!}

        </div>
    </div>
@endsection
谢谢你的时间!

1 个答案:

答案 0 :(得分:2)

您的要求正在

namespace POS\Http\Requests;

你的控制器在哪里

use POS\Http\Request\CategoriaFormRequest;

将其更改为:

use POS\Http\Requests\CategoriaFormRequest;