Is it possible to add a parameter to the url
from the route Controller?
For example my url is: myshop.com/order-finished
And his method controller is:
getOrderFinished() {
// I want add this param
myshop.com/order-finished?order_number=W00034335
}
I want the final url myshop.com/order-finished?order_number=W00034335, but I must add the parameter order_number
from the controller method.
EDIT: no redirections please
Is it possible to add a param to the url from the route Controller?
Yes, it is possible. You can redirect route if you want to go to that url. Say the route name is 'order-finished' then in the controller you can do the following :
return redirect()->route('order-finished', ['order_number'=>'W00034335']);
The implication is that the order_number will be appended as a query parameter to that route.
PS: This answer goes specifically if you are referring to a request call to a route, and not the general url configuration of your app.
Yes:
redirect('order-finished?order_number=W00034335');
Simply, use redirect()->to()
method.
public function getOrderFinished(){
// your parameter value
$param = W00034335;
return redirect()->to('myshop.com/order-finished?order_number='.$param);
}
You should try this:
use Illuminate\Support\Facades\Redirect;
$paramData = 'W00034335';
return Redirect::to('/order-finished?order_number='. $paramData);
Hope this help for you !!!
To add a parameter to the url you need to define in route file
<?php
Route::get('/order-finished/order_number/{id}', [
'as' => 'front.order.detail',
'uses' => 'OrderController@getOrderDetail'
]);
{{ route('front.order.detail',$order['id']) }}
?>
Since all (or most) of the answers are using redirects, I'll try something else. I feel like this is a very clean approach.
In your routes/web.php file, insert this:
Route::get('order/{id}', 'OrderController@show');
And then in your OrderController, have this:
public function show($id)
{
$order = Order::find($id);
return view('orders.show')->with('order', $order);
}
It's the basic idea of routing, as you can find in the documentation here.
Modify the naming conventions how you will!