我正在尝试将数据插入数据库,既不显示错误也不将数据保存到我的数据库中,下面是代码。这是创建刀片 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')); }
1 回答
GCT1015
TA贡献1827条经验 获得超4个赞
你忘了在 Camp 之后添加括号它应该是这样的:
$camp = new Camp();
$camp->name = $request->name;
$camp->district = $request->district;
$camp->save();
- 1 回答
- 0 关注
- 114 浏览
添加回答
举报
0/150
提交
取消