表单未随 Laravel Collection 提交

时间:2021-06-21 19:23:36

标签: html laravel forms laravel-collection

我正在尝试使用 Laravel v.8 为新帖子创建一个简单的创建表单。

第一次尝试使用该表单时,它工作正常,但是在我尝试使用 CDN 在线添加 TinyMCE 并删除它后,该表单因某种原因停止工作。

这是我的刀片

<div class="box-body">
  {!! Form::model($post, [ 'method' => 'POST', 'route' => 'storepost' ]) !!}

  <div class="form-group {{ $errors->has('title') ? 'hasError' : '' }}">
    {!! Form::label('title') !!} {!! Form::text('title', null, ['class' => 'form-control']) !!}
  </div>

  @if($errors->has('title'))
  <span class="help-block"> {{ $errors->first('title') }} </span> @endif

  <div class="form-group {{ $errors->has('kategori') ? 'hasError' : '' }}">
    {!! Form::label('kategori') !!}
    <br> {!! Form::select('kategori', ['anime' => 'Anime', 'news' => 'News', 'medicine' => 'Medicine'], null, ['placeholder' => 'Pick a category...']) !!}
  </div>

  @if($errors->has('kategori'))
  <span class="help-block"> {{ $errors->first('kategori') }} </span> @endif

  <div class="form-group {{ $errors->has('body') ? 'hasError' : '' }}">
    {!! Form::label('body') !!} {!! Form::textarea('body', null, ['class' => 'form-control']) !!}
  </div>

  @if($errors->has('body'))
  <span class="help-block"> {{ $errors->first('body') }} </span> @endif

  <div class="form-group">
    {!! Form::submit('Save', ['class' => 'btn btn-primary']); !!}
  </div>

  {!! Form::close() !!}
</div>

这是我的控制器

public function create(Post $post)
{
    return view('layouts.backend.admin.create', compact('post'));
}

这是“dd”不起作用的地方。

public function store(Requests\PostRequest $request)
{
    $request->user()->posts()->create($request->all());

    return redirect('admin/all')->with('message', 'Data saved!');
}

这是我的路线

Route::get('/admin/create', [App\Http\Controllers\BackEnd\BlogController::class, 'create'])->name('createpost');

Route::post('/admin/store', [App\Http\Controllers\BackEnd\BlogController::class, 'store'])->name('storepost');

我也有其他路线需要更新,但效果很好。

1 个答案:

答案 0 :(得分:0)

我忘记更改 PostRequest 中的某些内容。

从这里:

'category' => 'required',

为此:

'kategori' => 'required',

不过,我不知道为什么在缺少这样的东西时它不会作为错误传递。

相关问题