【发布时间】:2019-04-19 11:28:36
【问题描述】:
我尝试让同时借出两本书成为可能,我的问题是只有一个值被转发。表单如下所示:
在视图中我尝试将字段重命名为“序列号2”,因为我认为他只是因为同名而忽略了第二个序列号。
这是我的观点:
<div class="card">
<div class="card-header">{{ __('Lend a book') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('borrow.store') }}">
@csrf
<div class="form-group row">
<label for="serialnumber" class="col-md-4 col-form-label text-md-right">{{ __('Please scan the Serialnumber of the book') }}</label>
<div class="col-md-6">
<input id="serialnumber" type="text" class="form-control{{ $errors->has('serialnumber') ? ' is-invalid' : '' }}" name="serialnumber" value="{{ old('serialnumber') }}" required @if (Session::has('autofocus')) autofocus @endif>
@if ($errors->any())
<div class="alert alert-danger">The book is not in stock.
<ul>
</ul>
</div>
@endif
</div>
</div>
<div class="form-group row">
<label for="serialnumber" class="col-md-4 col-form-label text-md-right">{{ __('') }}</label>
<div class="col-md-6">
<input id="serialnumber" type="text" class="form-control{{ $errors->has('serialnumber') ? ' is-invalid' : '' }}" name="serialnumber" value="{{ old('serialnumber') }}" required @if (Session::has('autofocus')) autofocus @endif>
@if ($errors->any())
<div class="alert alert-danger">The book is not in stock..
<ul>
</ul>
</div>
@endif
</div>
</div>
<div class="form-group row">
<label for="comment" class="col-md-4 col-form-label text-md-right">{{ __('comment') }}</label>
<div class="col-md-6">
<!-- <input id="ma_id" type="text" class="form-control{{ $errors->has('ma_id') ? ' is-invalid' : '' }}" value="{{ old('ma_id') }}" required> -->
<input id="comment" type="text-field" class="form-control" name="comment" placeholder="Test">
@if ($errors->has('comment'))
<span class="invalid-feedback">
<strong>{{ $errors->first('comment') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<label for="ma_id" class="col-md-4 col-form-label text-md-right">{{ __('scan membercard to identify yourself') }}</label>
<div class="col-md-6">
<!-- <input id="ma_id" type="text" class="form-control{{ $errors->has('ma_id') ? ' is-invalid' : '' }}" value="{{ old('ma_id') }}" required> -->
<input id="ma_id" type="password" class="form-control" name="ma_id" required>
@if ($errors->has('ma_id'))
<span class="invalid-feedback">
<strong>{{ $errors->first('ma_id') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('send') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
这是我的控制器:
public function store(bookRequest $request)
{
//if( !book::find($request->get('serialnumber'))->exists() ) {
$this->middleware('guest');
request()->validate([
'serialnumber' => 'required',
'serialnumber' => 'required',
'ma_id' => 'required'
]);
book::create($request->all());
return redirect()->route('book.index');
}
没有错误,但问题是他如上所述只将一个序列号写入数据库,而完全忽略了进入第二个字段的另一个序列号。我的问题是我必须调整什么,以便可以将具有相同数据的第二个序列号写入数据库。
【问题讨论】: