【发布时间】:2020-12-08 15:21:47
【问题描述】:
我认为我正在发送所有重要的变量来查看,但没有。我不知道为什么会收到此错误:缺少 [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', compact('proform', 'query'))
->with('success','Product deleted successfully');
}
}
这是视图 proforms.edit 的所有代码,它会生成该错误。
@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');
【问题讨论】:
-
你需要通过这条路由
proforms.edit'传递id参数,但我认为你刚刚删除了这个id,所以如果你传递id参数那么它就不起作用了,所以重定向到另一个路由,比如@ 987654326@ -
我没有删除 id。 $proforom->id 没有从视图发送到这个控制器。在 $proform 中,我只有带有列名的空数组。但是当我将 $proform 添加到路由时,我收到错误 404。
标签: php laravel frameworks web-frameworks