3

I have an application in which you can choose between multiple customers. Choosing a customer will generate following URL:

http://localhost:8000/customer/CUSTOMER_NAME

From there on, I would like to choose a specific sub-page (e.g.: the support page)

How do I generate the following link:

http://localhost:8000/customer/CUSTOMER_NAME/support

So far, I always lose my CUSTOMER_NAME parameter, and I do not know how to keep it.

The framework I use is Laravel 5.

Any ideas?

2
  • if you have code, please include it as code in the question, not as an image. Commented Nov 12, 2015 at 10:10
  • 1
    vote up for descriptive question Commented Nov 12, 2015 at 10:29

3 Answers 3

2

You shall do this by passing the url param to the view by

I believe you have something like this in your route

Route::get('customer/{id}', 'yourController@yourFunctionName');

Then, in your controller, you may have

public function yourFunctionName($id)
{
    return view('yourViewName')->with('id', $id);
}

Then from your view can simply do this to generate a url like this

<a href="customer/{id}/support">Click here</a>

To have the url like below

http://yourprojectname/customer/18/support

Advice : Use the Primary key or any unique field rather than using name to avoid some future issues.

Also you shall use helpers to generate url's

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Sulthan Allaudeen! (Both for the answer and the advice) ... @Domysee: I'll take your remark of code as an image into account next time!
2

Are you using named routes?

Route::get('customer/{name}', ['as' => 'customer.index', 'uses' => 'CustomerController@index']);

You could set up a new route like this:

Route::get('customer/{name}/support', ['as' => 'customer.support', 'uses' => 'CustomerController@support']);

with a method for the support section

public function support($name) {
    return view('customer.support', [
        'name' => $name,
    ]);
}

And in your layout you can link to the route.

<a href="{{ route('customer.support', $name) }}">Support</a>

2 Comments

Hi James, thanks for the input! I'm rather new to Laravel, so for now I'll stick with Sulthan's answer. However, I will look into those named routes, they look interesting!
Vote up for clear answer and welcome to stackoverflow
0
{{ route('pages.home', $array_of_custom_params) }}

This will generate the link:

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.