I have three models
Produit Model :
public function propositions ()
{
return $this->belongsToMany(PropoCom::class, 'propo_com_produits',
'propo_com_id','produit_id',)->withPivot('tva', 'prix_unitaire_ht', 'quantite', 'reduction', 'prix_revient');
}
PropoCom Model :
public function produits ()
{
return $this->belongsToMany(Produit::class, 'propo_com_produits',
'propo_com_id','produit_id',)->withPivot('tva', 'prix_unitaire_ht', 'quantite', 'reduction', 'prix_revient');
}
public function propoCom_produit()
{
return $this->hasMany(PropoCom_produit::class);
}
PropoCom_produit Model :
public function produits(){
return $this->belongsTo(Produit::class, 'produit_id');
}
public function proposition (){
return $this->belongsTo(PropoCom::class,"propo_com_id");
}
PropositionController which allows me to modify Produit associated with PropoCom :
public function edit($id)
{
$commerce = PropoCom_produit::findOrfail($id);
$proposition = $commerce->proposition;
return view('layouts.commerce.edit-propo', compact('commerce', 'proposition'));
}
Route to edit :
Route::get('/commerce/new/proposition/details/{propo_com_id}/edit'[App\Http\Controllers\PropositionController::class, 'edit'])->name('proposition.produit.edit');
My Blade view with link allowing me to modify Produit associated with PropoCom:
<a href="{{ route('proposition.produit.edit', $proposition->id) }}" target="_blank" class="btn btn-primary btn-sm"><i class="fa fa-pen"></i></a>
But when I hover over the icon to see the link it retrieves the PropoCom ID from the PropoCom_Product ID link and when I click on it I get a 404 error NOT FOUND
Any ideas ?
It seems like you are trying to pass the
PropoCom_produitID to theeditmethod ofPropositionController, but in your route definition, you are usingpropo_com_idas a parameter. This might be causing the issue.In your route definition, you should use the
PropoCom_produitID as a parameter. Here's how you can do it:And in your Blade view, you should pass the
PropoCom_produitID to the route:This way, when you click the link, it will pass the correct
PropoCom_produitID to theeditmethod ofPropositionController.