2

I have this problem where i need to get this kind of url localhost:8000/purchaseOrder/3/purchase/1 if i typed it manually it worked but when i make the laravel automatically create the url it got error and end up with localhost:8000/purchaseOrder/$data-%3Eid/payable/$p-%3Eid

this are my routing

Route::get('/purchaseOrder/{id}/payable/{he}', 'AjaxController@purchaseOrder');

this are my controller (so far all i wanted is just respond to the url i gave)

function purchaseOrder($id,$he)
{
  echo $id." | ".$he;
}

this are my view

<a href="{{ url('purchaseOrder/$data->id/payable/$p->id') }}"><button type="button" class="btn btn-success btn-sm my-1" name="button">Create Purchase Order</button></a><br>
1
  • you need to concatenate your variables with the url 'purchaseOrder/'.$data->id.'/payable/'.$p->id.' with the . Commented Sep 12, 2019 at 8:53

2 Answers 2

5

change view code :

<a href="{{ url('purchaseOrder/'.$data->id.'/payable/'.$p->id.') }}"><button type="button" class="btn btn-success btn-sm my-1" name="button">Create Purchase Order</button></a><br>

another way is this:

set name for route

Route::get('/purchaseOrder/{id}/payable/{he}', 'AjaxController@purchaseOrder')->name('purchaseOrder');

and in view:

<a href="{{ route('purchaseOrder',[$data->id,$p->id]) }}">
Sign up to request clarification or add additional context in comments.

Comments

1

You can use two methods to achieve this.

(1) Use route() method: Pass route name

<a href="{{ route('purchaseOrder',['id' => $data->id,'he' => $p->id]) }}"><button type="button" class="btn btn-success btn-sm my-1" name="button">Create Purchase Order</button></a>

(2) Use url() method: pass URL of the route

<a href="{{ url('purchaseOrder/'.$data->id.'/payable/'.$p->id.') }}"><button type="button" class="btn btn-success btn-sm my-1" name="button">Create Purchase Order</button></a><br>

Please update your route with name for first route() method

Route::get('/purchaseOrder/{id}/payable/{he}', 'AjaxController@purchaseOrder')->name('purchaseOrder');

2 Comments

Naming of the route must be the same with the purchaseOrder or i could be anything?
Yes, you can use anything like (->name('xyz')). but in the route() method, you should pass xyz like (route('xyz')). @MartinChristopher

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.