我想知道有没有办法通过隐藏输入(不使用路由参数)将URL id传递给表单?我得到了这个表单网址:http://1mark.dev/jurnal/create?edisi=1
由此网址生成:<a href="../jurnal/create?edisi={{$edisi->id}}" class="btn btn-primary">Tambah Jurnal</a>
我想获取ID并将其传递给创建表单视图:
@if (isset($jurnal))
{!! Form::hidden('id', $jurnal->id) !!}
@endif
@if ($errors->any())
<div class="form-group {{ $errors->has('judul') ? 'has-error' : 'has-success' }}">
@else
<div class="form-group">
@endif
{!! Form::label('judul', 'Judul :', ['class' => 'control-label']) !!}
{!! Form::text('judul', null, ['class' => 'form-control']) !!}
@if ($errors->has('judul'))
<span class="help-block">{{ $errors->first('judul') }}</span>
@endif
</div>
@if ($errors->any())
<div class="form-group {{ $errors->has('penulis') ? 'has-error' : 'has-success' }}">
@else
<div class="form-group">
@endif
{!! Form::label('penulis', 'Penulis :', ['class' => 'control-label']) !!}
{!! Form::text('penulis', null, ['class' => 'form-control']) !!}
@if ($errors->has('penulis'))
<span class="help-block">{{ $errors->first('penulis') }}</span>
@endif
</div>
@if ($errors->any())
<div class="form-group {{ $errors->has('abstrak') ? 'has-error' : 'has-success' }}">
@else
<div class="form-group">
@endif
{!! Form::label('abstrak', 'Abstrak :', ['class' => 'control-label']) !!}
{!! Form::textarea('abstrak', null, ['class' => 'form-control']) !!}
@if ($errors->has('abstrak'))
<span class="help-block">{{ $errors->first('penulis') }}</span>
@endif
</div>
@if ($errors->any())
<div class="form-group {{ $errors->has('file') ? 'has-error' : 'has-success' }}">
@else
<div class="form-group">
@endif
{!! Form::label('file', 'File Jurnal (PDF) :') !!}
{!! Form::file('file') !!}
@if ($errors->has('file'))
<span class="help-block">{{ $errors->first('file') }}</span>
@endif
</div>
{!! Form::hidden('id', $edisi->id) !!}
<div class="form-group">
{!! Form::submit($submitButtonText, ['class' => 'btn btn-primary form-control']) !!}
</div>
我的问题是,如何将edisi id传递给视图,以便我可以将其传递给控制器..谢谢
创建控制器:
public function create(Edisi $edisi) {
return view('jurnal/create', compact('edisi'));
}
商店控制器:
public function storejurnal(JurnalRequest $request) {
$input = $request->all();
//Input PDF
if ($request->hasFile('file')) {
$input['file'] = $this->uploadPDF($request);
}
//Insert data jurnal
$id = $request->id;
$jurnal = Edisi::findOrFail($id)->jurnal()->create($input);
return redirect('jurnal');
}
答案 0 :(得分:1)
您可以将变量传递给类似
的视图return view('your view')->with('edisi', \Request::get('edisi'));
答案 1 :(得分:0)
您需要像往常一样将变量传递给视图:
return view('my.view', compact('edisi'));
然后您可以将此变量传递给控制器。像现在一样在视图中使用它:
{!! Form::hidden('id', $edisi->id) !!}
在控制器中使用它:
public function someAction(Request $request)
{
$id = $request->id;
}