Probably a basic question but I can't seem to get it.
I am wanting to grab the variable in my url to my controller.
// index view
@foreach ($paymentInfos as $p)
<tr>
<td><a href="{{ URL::action('AdminController@getPackingSlip', array('order_id' => $p->order_id)) }}"> {{ $p->order_id }}</a></td>
<td>{{ $p->lastname }} {{ $p->firstname }}</td>
<td>{{ $p->buyer_email }}</td>
</tr>
@endforeach
// route
Route::get('printpackingslip', 'AdminController@getPackingSlip');
// Controller
class AdminController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function getPackingSlip()
{
$rules = array('order_id' => 'order_id');
return View::make('admin.packingslip')->with($rules);
}
}
When you click on the link it goes to www.domain.com/printpackingslip?order_id=3
I do not know how to grab the order_id=3 in my controller.
Also would I be better off using the :(num) to generate a URI of /printpackingslip/3 or does it not matter?
For example:
// in my first view have:
<td><a href="{{ URL::to('printpackingslip', array('order_id' => $p->order_id)) }}"> {{ $p->order_id }}</a></td>
// then my route:
Route::get('printpackingslip/(:num)', 'AdminController@getPackingSlip');
Thanks!
Is this Laravel 4? Let's review it all:
Route:
Route::get('printpackingslip/{order_id}', 'AdminController@getPackingSlip');
Controller:
class AdminController extends BaseController {
public function getPackingSlip($order_id)
{
return "you selected $order_id";
}
}
View:
@foreach ($paymentInfos as $p)
...
<td><a href="{{ URL::route('printpackingslip', array('order_id' => $p->order_id)) }}"> {{ $p->order_id }}</a></td>
...
@endforeach
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With