Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

westag's avatar

laravel 5 view composer and url parameters

Hello people, how are you? I'm new to Laravel. So far I like it, but I have a problem.

I want to create a category menu in my left sidebar. When you click a random category it shows all the children from one category. See above.

category
category ( clicked )
    - category 
    - category 
        - category
        - category
    - category  
category
category

table categories

id      parent     name
1   0          category 1
2   0           category 2
3       1              child category   

I thought maybe it is a good idea to create a view composer, because the category menu is shown on all pages. Problem is that I need the data from the url for ex( website.com?id=23&blabla=sd), so I can retrieve all the children from the category I clicked.

How can i access the GET variables in a view composer or what is a better way to do this in Laravel ?

0 likes
3 replies
martinbean's avatar

@westag You can retrieve query string parameters from the Request service:

$category = Request::query('category');

If you use the façade, be sure to import it at the top of your view composer (use Request;).

1 like
westag's avatar
westag
OP
Best Answer
Level 1

Thanks for your answer.

Actually i needed the Route service to get the job done.

$current_params = Route::current()->parameter('hierarchy');

My route is

Route::get('category/{hierarchy}', 'CategoriesController@index')->where('hierarchy', '(.*)?');

4 likes
74644p's avatar

Hi Westag,

Did you by any change solve this issue.

I am having same issue.

Thanks in advance, Sing*

Please or to participate in this conversation.