Laravel routing and route parameters

Sina

I have route defined in my route.php file like below:

Route::get('{test1}/{test2}/{test3}', function($test1, $test2, $test3) {
    $result = [$test1, $test2, $test3];
    return view('view', compact('result'));
});

it works fine in my controller but on the view part when i see it in the browser when i just write something like this in browser:

http://localhost/mysitefolder/public/test1/test2/test3

it loads the view and pass all the data but it gets all of my assets like my stylesheets, images and scripts from a url like below:

http://localhost/mysitefolder/public/test1/test2/js/jquery.js

why is that happing?
thanks in advance!

KKK

Two solutions either use a / in the start of your URLs so that relative addressing is not used or use laravel's helper functions {{ asset('/js/script.js') }}.

When you do not use '/' in the beginning your url, it is treated as if it was a relative address and current location is added in its start.

Sometimes even '/' won't work if your application is not served on Root level. For example you have your application at http://localhost/yourapplication then / would refer to your localhost instead of application, that's why best way is to use laravel's helper function.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

laravel routing / How i can use array of parameters in route

Laravel: Routing parameters not working

routing in .net 3.0 - route parameters and action parameters

Route Parameters in laravel 5.1

Variables as Route Parameters (LARAVEL)

Laravel Route with n parameters

Laravel - Parameters are not forward by the route

Laravel multiple route parameters

Web.Api routing additional parameters to route

Laravel API URL Parameters and Routing

route binding for optional parameters in laravel

Laravel Missing required parameters for Route:

Laravel 8 route with multiple parameters

Laravel 5 route parameters not send

Laravel CRUD delete route parameters

Redirect route with two parameters in WITH [Laravel]

Laravel Pages with Categories Route Parameters

Optional parameters in route - Laravel 5

Missing required parameters for a route in laravel

Laravel Routing URL Parameters with POST Request

Proper Laravel routing with absence of URI parameters

Routing with multiple parameters in laravel disrupt other one

Angular2 routing configuration (route with two parameters)

Possible to log a route with query parameters before routing in Angular

Angular 4 routing: Is it possible to add constraints to route parameters?

correct syntax for route name when routing with annotations in presence or url parameters

Attribute routing - can I specify default values for parameters not in the route

Problem with routing when I put some route parameters

Laravel - LoginController | How to set $redirectTo route with parameters?