它既不显示错误,也不将数据保存到我的数据库PHP Laravel中?
我正在尝试将数据插入数据库,但未显示错误,也未将数据保存到我的数据库中。下面是代码。这里是创建刀片php页面它既不显示错误,也不将数据保存到我的数据库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
@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();