我尝试用jquery表单更新请求数据我只得到错误,我发现任何解决但不是。 那是我的观点页面。 修改按钮
<button type="button" class="btn btn-pill btn-outline-primary btn-sm open_model" data-toggle="modal" data-target="#editModal" data-id="{!! $d->id !!}"
data-description="{!! $d->description !!}"
data-sorting="{!! $d->sorting !!}">
<i class="fa fa-pencil"></i> Edit
</button>
(适用index.blade.php)
{!! Form::open(['url' => 'divisions/'.$divisions->id, 'method' => 'PUT', 'class' => 'form-horizontal']) !!}
<div class="form-group row">
<label class="col-md-3 col-form-label" for="name">Division</label>
<div class="col-md-9">
<input type="text" id="description" name="description" value="{{old('description')}}" class="form-control" placeholder="Enter Division..">
<input type="hidden" class="form-control" name="id" id="id">
<span class="help-block"></span>
@if ($errors->has('description'))
<span class="text-danger">{{ $errors->first('description') }}</span>
@endif
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="sort">Sort</label>
<div class="col-md-9">
<input type="text" id="sorting" name="sorting" value="{{old('sorting')}}" class="form-control" placeholder="Enter Sort..">
<span class="help-block"></span>
@if ($errors->has('sorting'))
<span class="text-danger">{{ $errors->first('sorting') }}</span>
@endif
</div>
</div>
<div class="pull-right">
<button type="submit" class="btn btn-pill btn-success btn-outline-success">
Update</button>
<button type="button" data-dismiss="modal" class="btn btn-pill btn-danger btn-outline-danger">
Close</button>
</div>
{!! Form::close() !!}
我的编辑弹出模型表单的jquery代码
$( document ).ready(function() {
$('#editModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var description = button.data('description')
var sorting = button.data('sorting')
var id = button.data('id')
var modal = $(this)
modal.find('.modal-body #description').val(description)
modal.find('.modal-body #sorting').val(sorting)
modal.find('.modal-body #id').val(id)
// alert('id');
});
});
DivisionController.php
public function index()
{
$divisions = Division::paginate(10);
return view('admin.division.index')->with('divisions', $divisions);
}
答案 0 :(得分:0)
$ divisions 是一个paginator对象,用于处理一个除法集合。 Paginator没有 $ id 参数 - 各个部门都有。
您需要遍历分页器才能获得单独的分部,然后您才能获取其ID,例如:
@foreach ($divisions as $division)
{{ $division->id }}
@endforeach