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



我正在尝试将数据插入数据库,既没有显示错误,也没有将数据保存到我的数据库中 以下是代码。 这是创建刀片 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

这是我手动输入从数据库中获取的数据时索引控制器工作正常的控制器 这是商店控制器,它也没有验证表单数据,我是新手我不知道该怎么做

public function store(Request $request)
{
$rules = array(
'name'    => 'required',
'district'=> 'required',
'address' => 'required',
'block'   => 'required|numeric',
'Population'   => 'required|numeric',
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
return Redirect::to('camp/create')
->withErrors($validator)
->withRequest(Request::except('password'));
} else {
// store
$camp = new Camp;
$camp->name       = Request::get('name');
$camp->district      = Request::get('district');
$camp->address = Request::get('address');
$camp->block      = Request::get('block');
$camp->population = Request::get('population');
$camp->save();
// redirect
Session::flash('message', 'Successfully created Camp!');
return view('campcamps',['camps'=>$camps]);
}
}

你忘了在营地后面添加括号,应该是这样的:

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

相关内容

  • 没有找到相关文章

最新更新