Hello, i'm using a open source template for my laravel app, these are in my routes.php file
Route::get('/articles', 'ArticlesController@index'); Route::get('articles/create', 'ArticlesController@create');
When i visit localhost:8000/articles, nothing on my web page breaks. But when i visit localhost:8000/articles/create, CSS, JS are not fully loaded on my web page and the page breaks.
Note: i also have a layout file which serves index.blade.php and create.blade.php
I don't know why it's breaking. Any help will be good.
Although I'm not very experienced in laravel, i know what's probably happening.
When visiting /articles, the css and js files are being served from root "/" directory still, in a relative manner (files are in their correct spot. /css/styles.css, for example).
However, when you go two directories deep in the url structure, the css and js files are being served relative to the current directory, which is now /articles/. Now the Web server is looking for these files in locations such as /articles/css/style.css, which obviously does not exist.
Possible fixes:
Example:
......
<title>app name</title>
<base href="http://www.yourdomain.com">
.......
Example :
......
<title>app name</title>
<base href="{{ route('index.show') }}"
......
With example of named route of the following in app/Http/routes.php
Route::get('/', ['uses' => 'IndexController@showIndex', 'as' => 'index.show']);
By using the route helper method above you are affording yourself being untied to your current routes and url structure. You could change the / to /newindex in routes and the base href in this template would remain the same provided the route name stays the same too.
RewriteEngine On
RewriteBase /
<script src="http://fulldomain.com/scripts/name.js">
And, finally :
<script src="{{ URL::asset('css/styles.css") }}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community