Wednesday, April 12, 2017

Why I can't obtain the CSS settings accessing to my Laravel application witohout vistual host?

I am very new in PHP and moreover in Laravel. I have the following problem.

I developed a Laravel 5.4 application (it is only a page with a user registration form) on my local environment setting this virtual host on my local apache server:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
    ServerName laravel.dev
</VirtualHost>

Using this virtual host it works fine, infact opening this URL http://laravel.dev/ it is opened the standard Laravel homepage (the one that shown the link to Laravel, Laracast, news, forge, github). The Laravel main page that I am not using.

Then I registered a controller toward the registration resource, this URL: http://laravel.dev/registration

This is the related route in the web.php:

Route::resource('/registration', 'RegistrationController');

related to this method of the RegistrationController.php class:

public function index(){

    return view('/registration/index');

}

And it is shown my registration page, it works fine.

The problem is that now I have to deploy it on my remote server where I have not a virtual host. So, before upload my application on the remote server, I tried to disable the previous virtual host on my local environemtn and I access to this application using the complete path.

So if I open this link:

http://localhost/HotelRegistration/public

this works fine and the standard Laravel page is opened !!!

The problem is that opening the registration page using this URL: http://localhost/HotelRegistration/public/registration

it appear without CSS because the CSS is related to this URL:

<link href="/css/app.css" rel="stylesheet">

that is accessible from http://laravel.dev/registration but not from http://localhost/HotelRegistration/public/registration. I think because there is the public folder in the middle or something like this.

Why am I finding this problem? How can I try to solve it and correctly access to my resource without using a virtual host?



via Andrea Nobili

Advertisement