4

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!

1 Answer 1

10

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
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant! It seems so simple once I see it... Thanks again!

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.