Php 缺少[Route:proforms.edit][URI:proforms/{proform}/edit]所需的参数
我想我正在发送所有重要的变量以供查看,但是没有。我不知道为什么会出现这样的错误:缺少[Route:proforms.edit][URI:proforms/{proform}/edit]所需的参数。 在这行代码中:Php 缺少[Route:proforms.edit][URI:proforms/{proform}/edit]所需的参数,php,laravel,frameworks,web-frameworks,Php,Laravel,Frameworks,Web Frameworks,我想我正在发送所有重要的变量以供查看,但是没有。我不知道为什么会出现这样的错误:缺少[Route:proforms.edit][URI:proforms/{proform}/edit]所需的参数。 在这行代码中:return redirect()->route('proforms.edit',compact('proform','query')) 这是用于此的控制器方法: public function destroy2(Proform $proform, $query2)
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', compact('proform', 'query'))
->with('success','Product deleted successfully');
}
}
这是view proforms.edit的所有代码,whitch会生成该错误
@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
您应该将“执行名称”传递到每个已执行的路由,如以下示例所示:
<form action="{{ route('proforms.update',['proform'=>$proform->id)] }}" method="POST">
@csrf
@method('PUT')
@csrf
@方法('PUT')
您的错误表明:
缺少[Route:proforms.edit][URI:proforms/{proform}/edit]所需的参数
请注意,您应该将proform
传递给路由重定向器
所以你应该改变
return redirect()->route('proforms.edit',compact('proform','query'))
->带有('success','Product deleted successfully');
到
return redirect()->route('proforms.edit'、//[$id]或$id)
->带有('success','Product deleted successfully');
您不应该使用compact方法来传递参数,因为它通常用于将数据传递给视图,所以您应该编写如下内容:
return redirect()->route('proforms.edit',[$proform,$query])
您可以命名route
proforms。编辑id
参数是必需的,因此您需要通过参数表。
捷径是:
return redirect()->back()->with('proform', $proform)->with('query', $query)
->with('success','Product deleted successfully');
另一种方法是,将参数作为隐藏字段传递。
在刀片服务器上,将此输入字段添加到表单
元素中:
<input type="hidden" name="proform_id" value="{{ $proform->id }}">
像这样的?这对我不起作用。return redirect()->route('proforms.edit',compact('proform','query','proform->id')->带有('success','Product deleted successfully');没有类似于eturn redirect()->route('proforms.edit',$proform->id)->with('success','Product deleted successfully')代码>,忘记压缩重定向到路由这是行不通的,因为他们刚刚删除了这个$id
,然后你就无法重定向到编辑路由,最好重定向到索引路由它不起作用。但我检查了$proform数组,它没有值,只有列名。为什么它不是嘲笑。我只从查询中删除了值,并没有删除形式id。但为什么形式id并没有从视图中发送。我的路由看起来是这样的,但如果我向它添加proform,它将返回错误404 page not found。路由::get('delete/proforms/{query2}','ProformController@destroy2')->name('proforms2.destroy2');您需要通过此路由proforms传递id参数。编辑'
,但我认为您刚刚删除了此id,因此如果传递id参数,它将不起作用,因此重定向到另一个路由,如return redirect()->route('proforms',compact('proform',query')
我没有删除id。$proforom->id没有从视图发送到此控制器。在$proform中,我只得到了带有列名的空数组。但是当我将$proform添加到路由中时,我得到了错误404。问题是视图正在将空数组$proform发送到此控制器。它只有列名。我必须将其发送到此控制器id,以便$proforom和它将是好的。但如何做到这一点。实际上你的错误是说缺少必需的参数,这意味着你传递了错误数量的参数。或者你传递了一个参数,它接收了两个参数
<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');