如何解决缺少[Route:proforms.edit]所需的参数[URI:proforms / {proform} / edit]
我认为我正在发送所有重要变量以供查看,但没有。我不知道为什么会收到此错误:[Route:proforms.edit] [URI:proforms / {proform} / edit]缺少必需的参数。
在这行代码上:return redirect()->route('proforms.edit',compact('proform','query'))
这是用于此的控制器方法:
public function destroy2(Proform $proform,$query2)
{
$query = DB::table('dynamic_fields')
->join('proforms','dynamic_fields.proform_id','=','proforms.id')
->select('dynamic_fields.*','proforms.*')
->where('proform_id',$proform->id)
->get();
DB::table('dynamic_fields')->where('id_pozycji','$query2')->delete();
return redirect()->route('proforms.edit','query'))
->with('success','Product deleted successfully');
}
}
这是用于查看proforms的所有代码。编辑器会生成该错误。
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Edytuj produkt</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('proforms.index') }}"> Wstecz</a>
</div>
</div>
</div>
@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('proforms.update',$proform->id) }}" method="POST">
@csrf
@method('PUT')
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Data wystawienia:</strong>
<input type="text" name="proformdate" value="{{ $proform->proformdate }}" class="form-control" placeholder="Data wystawienia">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Kontrahent:</strong>
<br>
<select class="form-controll" name="user_id">
@foreach($users as $user)
<option value="{{$user->id}}">{{$user->showname}}</option>
@endforeach
</select>
<br>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Waluta:</strong>
<br>
<select class="form-controll" name="currency_id">
@foreach($currencys as $currency)
<option value="{{$currency->id}}">{{$currency->currency}}</option>
@endforeach
</select>
<br>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Forma płatności:</strong>
<br>
<select class="form-controll" name="form_id">
@foreach($forms as $form)
<option value="{{$form->id}}">{{$form->form}}</option>
@endforeach
</select>
<br>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Data sprzedaży:</strong>
<input type="text" name="selldate" value="{{ $proform->selldate }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Termin płatności:</strong>
<input type="text" name="paymentdate" value="{{ $proform->paymentdate }}" class="form-control" placeholder="Termin płatności">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Forma płatności:</strong>
<input type="text" name="paymentmethod" value="{{ $proform->paymentmethod }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Miejsce wystawienia:</strong>
<input type="text" name="city" value="{{ $proform->city }}" class="form-control" placeholder="Status">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Status:</strong>
<input type="text" name="status" value="{{ $proform->status }}" class="form-control" placeholder="Status">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Uwagi:</strong>
<input type="text" name="name" value="{{ $proform->comments }}" class="form-control" placeholder="Uwagi">
</div>
</div>
<div class="pull-left" style="margin: 35px;">
<h3>Pozycje faktury</h3>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Nazwa towaru lub usługi:</strong>
<input type="text" name="name" value="{{ $proform->name }}" class="form-control" placeholder="Data wystawienia">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>PKWiU:</strong>
<input type="text" name="PKWIU" value="{{ $proform->PKWIU }}" class="form-control" placeholder="Kontrahent">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Ilość:</strong>
<input type="text" name="quantity" value="{{ $proform->quantity }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Jednostka:</strong>
<input type="text" name="unit" value="{{ $proform->unit }}" class="form-control" placeholder="Termin płatności">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Cena netto jednostki:</strong>
<input type="text" name="netunit" value="{{ $proform->netunit }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Netto razem:</strong>
<input type="text" name="nettotal" value="{{ $proform->nettotal }}" class="form-control" placeholder="Status">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Stawka VAT:</strong>
<input type="text" name="VATrate" value="{{ $proform->VATrate }}" class="form-control" placeholder="Status">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Brutto jednostka:</strong>
<input type="text" name="grossunit" value="{{ $proform->grossunit }}" class="form-control" placeholder="Status">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Brutto razem:</strong>
<input type="text" name="grosstotal" value="{{ $proform->grosstotal }}" class="form-control" placeholder="Status">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Zapisz</button>
</div>
</div>
</form>
<table class="table table-bordered">
<tr>
<th scope="col">@sortablelink('id','Numer')</th>
<th scope="col">@sortablelink('name','Nazwa pozycji')</th>
<th scope="col">@sortablelink('PKWIU','PKWiU')</th>
<th scope="col">@sortablelink('quanity','Ilość')</th>
<th scope="col">@sortablelink('unit','Jednostka')</th>
<th scope="col">@sortablelink('netunit','Jednostka netto')</th>
<th scope="col">@sortablelink('nettotal','Razem netto')</th>
<th scope="col">@sortablelink('VATrate','Stawka VAT')</th>
<th scope="col">@sortablelink('grossunit','Brutto jednostka')</th>
<th scope="col">@sortablelink('grosstotal','Brutto razem')</th>
<th width="280px">Akcja</th>
</tr>
@foreach ($query as $query2)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $query2->name }}</td>
<td>{{ $query2->PKWIU }}</td>
<td>{{ $query2->quantity }}</td>
<td>{{ $query2->unit }}</td>
<td>{{ $query2->netunit }}</td>
<td>{{ $query2->nettotal }}</td>
<td>{{ $query2->VATrate }}</td>
<td>{{ $query2->grossunit }}</td>
<td>{{ $query2->grosstotal }}</td>
<td>
<form action="{{ route('proforms2.destroy2',$query2->id_pozycji) }}" method="GET">
@can('product-edit')
<a class="btn btn-primary" href="{{ route('proforms.edit',$query2->id_pozycji) }}">Edytu</a>
@endcan
@csrf
@method('GET')
@can('product-delete')
<button type="submit" class="btn btn-danger">Usuń</button>
@endcan
</form>
</td>
</tr>
@endforeach
</table>
<p class="text-center text-primary"><small>ARTplus 2020</small></p>
@endsection
这是此视图和控制器的路线:
Route::get('delete/proforms/{query2}','ProformController@destroy2')->name('proforms2.destroy2');
解决方法
您的错误表明:
缺少[Route:proforms.edit] [URI:proforms / {proform} / edit]所需的参数。
请注意,您应将proform
传递给路由重定向器
所以你应该改变
return redirect()->route('proforms.edit',compact('proform','query'))
->with('success','Product deleted successfully');
到
return redirect()->route('proforms.edit',// [$id] or $id )
->with('success','Product deleted successfully');
,
您不应该使用 compact 方法来传递参数,因为它通常用于将数据传递给视图,因此您应该编写如下代码:
return redirect()->route('proforms.edit',[$proform,$query])
,
您将路由proforms.edit
命名为id
参数是必需的,因此您需要传递参数。
快捷方式是:
return redirect()->back()->with('proform',$proform)->with('query',$query)
->with('success','Product deleted successfully');
另一种方法是将参数作为隐藏字段传递。
在您的刀片上,将此 input 字段添加到form
元素中:
<input type="hidden" name="proform_id" value="{{ $proform->id }}">
然后您的控制器代码将类似于:
return redirect()->route('proforms.edit',$request->proform_id)
->with('proform',$proform)
->with('query',$query)
->with('success','Product deleted successfully');
,
您应该将执行名称传递给每个具有以下示例所示效果的路线:
<form action="{{ route('proforms.update',['proform'=>$proform->id)] }}" method="POST">
@csrf
@method('PUT')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。