我在存储数据时遇到问题。我尝试在工作站表中添加数据。没有错误,但没有添加数据。我认为我的代码没有任何错误,但是如果您可以调试它,那将是一个很大的帮助。
WorkstationController
public function store(Request $request)
{
$this->validate($request, [
'ws_number' => 'required|integer',
'floor_id' => 'required|integer'
]);
$workstation = Workstation::create([
'ws_number' => $request->input('ws_number'),
'floor_id' => $request->input('floor_id')
]);
return redirect()->route('workstation.index')->with('success' , 'Workstation added successfully');
}
workstation.blade.php添加模式
<!-- Add WS Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModalLabel">Add Workstation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{!! Form::open(['route' => 'workstation.store', 'method' =>'POST']) !!}
{!! Form::label('Workstation Number:') !!}
{!! Form::text('ws_number', null, ['class' => "form-control"]) !!}
{!! Form::label('Location and Floor:') !!}
<select class="form-control">
@foreach($floors as $floor)
<option value="{{$floor->id}}">{{ $floor->floor }} Floor, {{ $floor->site }}</option>
@endforeach
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" style="margin-top:20px" data-dismiss="modal">Cancel</button>
{!! Form::submit('Add workstation', ['class' => 'btn btn-primary', 'style' => 'margin-top:20px']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
工作站型号
class Workstation extends Model
{
protected $fillable = [
'id',
'ws_number',
'floor_id'
];
public function floor()
{
return $this->belongsTo('App\Floor');
}
}