我正在嘗試將數(shù)據(jù)插入數(shù)據(jù)庫,既不顯示錯(cuò)誤也不將數(shù)據(jù)保存到我的數(shù)據(jù)庫中,下面是代碼。這是創(chuàng)建刀片 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這是控制器,當(dāng)我手動(dòng)輸入它從數(shù)據(jù)庫中獲取的數(shù)據(jù)時(shí),索引控制器工作正常這里是商店控制器,它也不驗(yàn)證表單數(shù)據(jù),我是新手,我不知道該怎么做 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貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
你忘了在 Camp 之后添加括號(hào)它應(yīng)該是這樣的:
$camp = new Camp();
$camp->name = $request->name;
$camp->district = $request->district;
$camp->save();
- 1 回答
- 0 關(guān)注
- 149 瀏覽
添加回答
舉報(bào)
0/150
提交
取消