Php Laravel-数据库存储功能不工作

Php Laravel-数据库存储功能不工作,php,laravel,crud,Php,Laravel,Crud,我在输入数据和弄清楚为什么我的数据没有存储到数据库中时遇到问题。我尝试使用资源路由和自定义路由代码,但似乎仍然没有任何效果。单击“提交”似乎只是刷新页面,没有显示错误 这是我的表格: <div class="container"> <div class="row"> <div class="col-md-12"> <nav class="navbar navbar-exp

我在输入数据和弄清楚为什么我的数据没有存储到数据库中时遇到问题。我尝试使用资源路由和自定义路由代码,但似乎仍然没有任何效果。单击“提交”似乎只是刷新页面,没有显示错误

这是我的表格:

<div class="container">
  <div class="row">
    <div class="col-md-12">                            
        <nav class="navbar navbar-expand-sm navbar-dark primary justify-content-between">
            <div class="navbar-brand text-dark">Create a Story</div>
        </nav>
        <hr class="mt-3">   
        <form action="{{route('story.store')}}" method="post">
            @csrf
            <div class="row">
                <div class="col col-lg-6">
                    <div class="form-group my-3">
                        <label for="title">Title</label><br>
                        <input type="text" name="title" id="title" class="w-100 form-control{{ $errors->has('title') ? ' is-invalid' : '' }}" value="{{ old('title') }}" required>
                        @if ($errors->has('title'))
                            <span class="invalid-feedback" role="alert"><strong>{{ $errors->first('title') }}</strong></span>
                        @endif
                    </div>
                </div>
                <div class="col col-lg-6">
                    <div class="form-group my-3">
                        <label for="category">Category</label><br>
                        <select name="category" id="category" class="w-100 form-control{{ $errors->has('category') ? ' is-invalid' : '' }}" value="{{ old('category') }}" required>
                            <option value="Active" selected>Select Category</option>
                            @foreach ($category as $item)
                                <option value="{{$item->id}}">{{$item->nama}}</option>
                            @endforeach
                        </select>
                        @if ($errors->has('category'))
                            <span class="invalid-feedback" role="alert"><strong>{{ $errors->first('category') }}</strong></span>
                        @endif
                    </div>
                </div>
                <div class="col col-lg-6">
                    <div class="form-group my-3">
                        <label for="thumbnail">Story Thumbnail <span class="text-muted">(Recomended size is 650 x 350 pixel)</span></label><br>
                        <input type="file" name="thumbnail" id="thumbnail">
                        @if ($errors->has('thumbnail'))
                        <span class="invalid-feedback" role="alert"><strong>{{ $errors->first('thumbnail') }}</strong></span>
                        @endif                            
                    </div>
                </div>

                <div class="col col-lg-12">                                
                    <div class="form-group mt-4">
                        <textarea id="text-content"  name="content" class="w-100 form-control{{$errors->has('content') ? ' is-invalid' : ''}}" id="content" rows="3" value="{{old('content')}}"></textarea>
                        @if ($errors->has('content'))
                        <span class="invalid-feedback" role="alert"><strong>{{ $errors->first('content') }}</strong></span>
                        @endif
                    </div>
                </div>
            </div>

            <div class="modal-footer pb-0">
                <div class="float-right">                        
                    <button type="submit" class="btn btn-outline-primary btn-md">Publish Story</button>
                </div>
            </div>
        </form>                               
    </div>
</div>
这就是路线:

Route::get('me/stories', 'PostController@index')->name('story');
Route::get('me/stories/create', 'PostController@create')->name('story.create');
Route::post('me/stories/store', 'PostController@store')->name('story.store');
Route::post('ck/image_upload', 'PostController@imageUpload')->name('ck.upload');
我根本没有收到任何错误消息,只是提交按钮没有任何作用。非常感谢

单击“提交”似乎只是刷新页面,没有显示错误

您的验证器返回到最后一页时出错

将此代码片段添加到刀片服务器

@if($errors->any())
    @foreach($errors->all()作为$error)
  • {{$error}}
  • @endforeach
@恩迪夫

另外,在提交前检查页面,进入网络选项卡(检查顶部的保留日志)并继续提交,您将获得发生情况的更多详细信息。

这是一个愚蠢的问题,但是您的帖子字段是否在
发布模式下定义为
可填充
?另外,请给出您问题中的
php artisan route:list
输出。@zlatan这里没有批量分配,很遗憾,这是个好主意,尽管
$post->category_id=request('category')更改为
$post->category\u id=$request->category更改其他请求();我在尝试$request('something')时出错,请尝试@Zar Ni Ko建议的方法您的表单没有设置为处理文件这应该是正在发生的情况,OP的表单至少没有设置为处理文件
Route::get('me/stories', 'PostController@index')->name('story');
Route::get('me/stories/create', 'PostController@create')->name('story.create');
Route::post('me/stories/store', 'PostController@store')->name('story.store');
Route::post('ck/image_upload', 'PostController@imageUpload')->name('ck.upload');