0

I have a route as:

Route::get('/edit/detail/{modelName}/{rowId}/{persId}',[AddPersInfoController::class,'editPersDetailTabs'])->name('edit_pers_detail');

and I'm calling it from a button in a table as:

Edit: This is the actual code on my page.

<td><a href="{{ route('edit_pers_detail',['Posting_history', $posting->id, $posting->pers_info_id] ) }}">
<button class="btn btn-icon btn-primary"> <i class="demo-pli-pencil fs-5"></i> </button>
 </a>
</td>`

In my AddPersInfoController class, I have a function:

public function editPersDetailTabs($modelName, $rowId, $persId){

  dd('Controller method executed');

  // Fetching record for editable components
  $model_name = 'App\Models\\' . $modelName;
        
  $detail = $model_name::where('id', $rowId)->first();
  dd($detail);

  return view('Pages.Persdata.add_all', compact('detail',   'postingHist',));
}

The method editPersDetailTabs is not getting called because none of the dd() statements show anything.

I have another route and method in the same syntax as this one; the only difference is that this accepts 3 parameters while the other one accepts two.

Rest everything is same. At least the method is being called in the other one.

Whenever I click the button; it just refreshes the page. Nothing else happens. I expect it to at least call the method.

Where could be the issue?

5
  • Welcome to SO ... you have described what you expect to be happening but what is actually happening? what result are you getting when trying to go to a URL that corresponds to that route? also what version of Laravel are you using? Commented Jan 21, 2024 at 16:28
  • return a 404 error? you tried to check in html if the url is correct? Commented Jan 21, 2024 at 18:23
  • Does your Laravel log (in storage/logs) show any errors when calling the route? Commented Jan 22, 2024 at 10:50
  • have you looked at the URL that is generated for that anchor tag? Commented Jan 22, 2024 at 15:18
  • I've updated the question. Could you all please take a look again? Commented Jan 22, 2024 at 16:38

2 Answers 2

0
<td>
  <a href="{{ route('edit_pers_detail',['Posting_history'=> $posting->id, 'posting_person_info' => $posting->pers_info_id] ) }}">
    <button class="btn btn-icon btn-primary"> <i class="demo-pli-pencil fs-5"></i> </button>
  </a>
</td>
Route::get('/edit/detail/{Posting_history}/{posting_person_info}',[AddPersInfoController::class,'editPersDetailTabs'])->name('edit_pers_detail');
public function functionName($Posting_history, $posting_person_info){
}
Sign up to request clarification or add additional context in comments.

Comments

-2

Try explicitly defining the route parameter names as keys in the array:

<a href="{{ route('edit_pers_detail',['modelName' => 'Posting_history', 'rowId' => $posting->id, 'persId' => $posting->pers_info_id] ) }}">

5 Comments

this is not correct at all ... the routing system understands segments of the path
I have only one route names as /edit/detail. All other routes have different names.
@lagbox... after testing in multiple versions of laravel... I confirmed that my answer was correct. Please can you provide proof that I'm wrong or are you just being contradictory?
@SikanderAli.. I think I see your issue... please see my updated answer.
well you just completely changed your answer, but Laravel's routing system is based on segments, which is why you got the downvotes ... here is the example directly from your answer: paste.laravel.io/cc212d13-1d33-40a9-b60e-55ecddac7756

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.