如何在创建类别时修复Laravel中的此错误

如何在创建类别时修复Laravel中的此错误,laravel,laravel-5,laravel-5.5,Laravel,Laravel 5,Laravel 5.5,我正在创建一个博客网站。我添加了一个快速更新的分类页面,但没有返回到索引:category.php,CategoriesController.php。我使用的是LaravelV5.5和OpenServer Category.php namespace应用程序; 使用Cviebrock\EloquentSluggable\Sluggable; 使用Illumb\Database\Elount\Model; 类类别扩展模型 { 受保护的$fillable=['title','slug',]; 公共函

我正在创建一个博客网站。我添加了一个快速更新的分类页面,但没有返回到索引:category.php,CategoriesController.php。我使用的是LaravelV5.5和OpenServer

Category.php

namespace应用程序;
使用Cviebrock\EloquentSluggable\Sluggable;
使用Illumb\Database\Elount\Model;
类类别扩展模型
{
受保护的$fillable=['title','slug',];
公共函数用户()
{
返回$this->belongtomany(
用户::类,
“id_idcat”,
“gid”,
“idcat”
);
}
公共功能()
{
返回[
“slug”=>[
“来源”=>“标题”
]
];
}
}
CategoriesController.php

namespace-App\Http\Controllers\Admin;
使用App\Category;
使用App\Http\Controllers\Controller;
使用\Http\Request;
使用视图;
类分类控制器扩展控制器
{
公共职能指数()
{
$categories=Category::all();
返回视图('admin.categories.index',['categories'=>$categories]);
}
公共函数create()
{
返回视图('admin.categories.create');
}
公共函数存储(请求$Request)
{
$this->validate$请求[
“标题”=>“必需”//
]);
类别::创建($request->all());
return redirect()->route('admin.categories.index');
}
}
create.blade.php

{!!表单::打开(['route'=>'categories.store'])
Добавляем категорию
Название
Назад
Добавить
{!!Form::close()!!}

我找不到错误。我做过几次类似的任务。

您的数据没有验证,因为没有名为title的输入,因为它名为cat,所以验证器会将您重定向回错误,但刀片服务器没有显示错误,所以您看不到它们

更改“创建”视图中字段的名称并添加错误,如下所示:

编辑:还将CSRF添加到表单中

create.blade.php

@if ($errors->any())
    <div class="alert alert-danger" role="alert">
        @foreach ($errors->all() as $input_error)
            {{ $input_error }}
        @endforeach
    </div>
@endif

    {!! Form::open(['route' => 'categories.store']) !!}  
    {{ csrf_field() }}
    <div class="box-header with-border">
        <h3 class="box-title">Добавляем категорию</h3>
      </div>
      <div class="box-body">
        <div class="col-md-6">
          <div class="form-group">
            <label for="exampleInputEmail1">Название</label>
            <input type="text" class="form-control" idcat="exampleInputEmail1" placeholder="" name="title">
          </div>
      </div>
    </div>
      <!-- /.box-body -->
      <div class="box-footer">
        <button class="btn btn-default">Назад</button>
        <button class="btn btn-success pull-right">Добавить</button>
      </div>
      <!-- /.box-footer-->
      {!! Form::close() !!}
@if($errors->any())
@foreach($errors->all()作为$input\u error)
{{$input_error}}
@endforeach
@恩迪夫
{!!Form::open(['route'=>'categories.store'])
{{csrf_field()}}
Добавляем категорию
Название
Назад
Добавить
{!!Form::close()!!}

您的数据没有验证,因为没有名为title的输入,因为它名为cat,所以验证器会将您重定向回错误,但刀片服务器没有显示错误,因此您看不到它们

更改“创建”视图中字段的名称并添加错误,如下所示:

编辑:还将CSRF添加到表单中

create.blade.php

@if ($errors->any())
    <div class="alert alert-danger" role="alert">
        @foreach ($errors->all() as $input_error)
            {{ $input_error }}
        @endforeach
    </div>
@endif

    {!! Form::open(['route' => 'categories.store']) !!}  
    {{ csrf_field() }}
    <div class="box-header with-border">
        <h3 class="box-title">Добавляем категорию</h3>
      </div>
      <div class="box-body">
        <div class="col-md-6">
          <div class="form-group">
            <label for="exampleInputEmail1">Название</label>
            <input type="text" class="form-control" idcat="exampleInputEmail1" placeholder="" name="title">
          </div>
      </div>
    </div>
      <!-- /.box-body -->
      <div class="box-footer">
        <button class="btn btn-default">Назад</button>
        <button class="btn btn-success pull-right">Добавить</button>
      </div>
      <!-- /.box-footer-->
      {!! Form::close() !!}
@if($errors->any())
@foreach($errors->all()作为$input\u error)
{{$input_error}}
@endforeach
@恩迪夫
{!!Form::open(['route'=>'categories.store'])
{{csrf_field()}}
Добавляем категорию
Название
Назад
Добавить
{!!Form::close()!!}