Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
它既不显示错误,也不将数据保存到我的数据库PHP Laravel中?_Php_Laravel_Laravel Blade_Laravel Controller_Laravel Datatables - Fatal编程技术网

它既不显示错误,也不将数据保存到我的数据库PHP Laravel中?

它既不显示错误,也不将数据保存到我的数据库PHP Laravel中?,php,laravel,laravel-blade,laravel-controller,laravel-datatables,Php,Laravel,Laravel Blade,Laravel Controller,Laravel Datatables,我正在尝试将数据插入数据库,但未显示错误,也未将数据保存到我的数据库中。下面是代码。这里是创建刀片php页面 @extends('layouts.app') @section('content') <h1>Create a Camp</h1> <!-- if there are creation errors, they will show here --> {{ HTML::ul($errors->all()) }} {{ Form::ope

我正在尝试将数据插入数据库,但未显示错误,也未将数据保存到我的数据库中。下面是代码。这里是创建刀片php页面

@extends('layouts.app')

@section('content')


<h1>Create a Camp</h1>

<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all()) }}

{{ Form::open(array('url' => 'camps')) }}


    <div class="form-group">
        {{ Form::label('name', 'Name') }}
        {{ Form::text('name', Request::old('name'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('district', 'District') }}
        {{ Form::text('district', Request::old('district'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('address', 'Address') }}
        {{ Form::text('address', Request::old('address'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('block', 'Block') }}
        {{ Form::text('block', Request::old('block'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('population', 'population') }}
        {{ Form::text('population', Request::old('population'), array('class' => 'form-control')) }}
    </div>


    {{ Form::submit('Create the Camp!', array('class' => 'btn btn-primary')) }}

{{ Form::close() }}

@endsection

您忘了在Camp后面添加括号,应该是这样的:

$camp = new Camp();
$camp->name       = $request->name;
$camp->district   = $request->district;
$camp->save();

您可以添加try-catch块并查看问题。您已返回
$validator
对象。但是,这应该是
$validator->errors()
以返回错误;但它仍然没有将数据保存到我的表中,也没有显示error@Deepak可以使用
$this->validate($request,$rules)
简化此示例。我不明白为什么你需要在这里手动创建一个错误包并返回一个重定向响应。。。
$camp = new Camp();
$camp->name       = $request->name;
$camp->district   = $request->district;
$camp->save();