0

I need to add orders to existing customers. From my customers.show view I use the following to visit the order form.

href="{{action('OrderController@create', $customer['id'])}}

The link of the page looks like:

/orders/create?2f10f8a0-30b9-11e8-8711-dd477b141226

I've been using the following route::get to no avail to be able to use this ID in my resource controller for Orders

Route::get('orders/create/{id}',  'OrderController@create');

Basically need to be able to to something along the lines of below to be able to show customer details while displaying the create order form as well but getting stuck on best way to pass the id through for the current customer

public function create(){
      $customer = Customer::find($id)
      return view('orders.create', compact('customer'));
}

2 Answers 2

1

With Laravel, you just need to add the parameters you specified in the route as function parameters, like below:

public function create($id){
      $customer = Customer::find($id)
      return view('orders.create', compact('customer'));
}
Sign up to request clarification or add additional context in comments.

3 Comments

I get an error. Missing argument 1 for App\Http\Controllers\OrderController::create()
Is the {id} still in your route definition?
Found the problem. My route definition wasn't correct. Fixed with Route::get('orders/{id}/create/', 'OrderController@create');
1

You are not passing the $id argument in the create function.

Change it to:

public function create( $id ){
    $customer = Customer::find($id)
    return view('orders.create', compact('customer'));
}

Comments

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.