Css and js files stalling on xampp using the Laravel framework - laravel

Xampp was working fine until this morning when internal css and js scripts stopped loading with them 'stalling' in the browser.
here is an example of my code:
<link rel="stylesheet" href="/css/main-styles.css }}">
A strange thing though, its loading fine if i use http://localhost/, but if I use the vhost I created (http://cars.web), it doesnt work.
As I say it was working, then all of a sudden stopped.
To add, when I paste http://cars.web/css/main-styles.css into the browser, it doesn't load. but that is the path.
Vhost is as follows:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp2/htdocs/cars/public"
ServerName cars.web
ErrorLog "logs/cars-error.log"
CustomLog "logs/cars-access.log" common
</VirtualHost>
UPDATE
When I remove that particular css file from my code, all the other css and js load fine
Please help.

You should use the asset() helper to avoid this kind of problems:
<link rel="stylesheet" href="{{ asset('css/main-styles.css') }}">
The asset function generates a URL for an asset using the current scheme of the request
https://laravel.com/docs/5.5/helpers#method-asset

After hours of searching for solutions I decided to reinstall xampp. The new version of xampp worked with the the same code.

Related

pretty-urls not working with XAMPP and Laravel 5.8

I use Laravel v5.8 and I was happy to use it in VMware with Ubuntu. Now I needed to change to a Windows Server 2012 with xampp.
There is one thing I cannot eliminate:
I can visit my page over
https://fancysubdomain.fancydomain.de/myapplikation/public
I've created links like
<a class="title" href="/entries/create" > FOO </a>
These links go to
https://fancysubdomain.fancydomain.de/entries/create
(watch the missing "myapplication" block) and Apache tells me that the requested URL was not found.
If I type
https://fancysubdomain.fancydomain.de/myapplikation/entries/create
in the address field of the browser it also doesn't work.
In the .env file, I've set
APP_URL= https://fancysubdomain.fancydomain.de/myapplikation/
I've edited \conf\app.php to
'url' => env('APP_URL', ' https://fancysubdomain.fancydomain.de/myapplikation/'),
There are no virtual hosts set up in httpd-vhosts.conf (I am not the administrator). Do I need to set them up to get what I want? Do I need to set up something else?
You should create a Vhost which should point to the public directory of you Laravel application.
It should look like this:
<VirtualHost *:80>
DocumentRoot "path/to/laravels/public/dir"
ServerName localhost
<Directory "path/to/laravels/public/dir">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
After this is done, the default .htaccess file will work and you have pretty url's.
I’ve finally found a solution. Thanks #J. Grunder stackoverflow
After I had changed these settings, I ran into a new problem with my links.
I had created links like
<a href=”/entries/create”>Create Entry</a>
Unfortunately, now the links pointed to
https://fancysubdomain.fancydomain.de/entries/create
(watch missing myapplikation element)
Of course, I could handle that with
<a href=”/myapplikation/entries/create”>Create Entry</a>
But there could be some problems if the user is at that place.
If somebody else runs in the same problem:
Use Laravel’s URL helper:
<a href=”{{ action('EntriesController#create') }}”>Create Entry</a>

laravel localhost and server work different with htaccess and public folder

After removing .htaccess from public to main, and renaming server.php to index.php all Asset links and links from the css background-image are wrong.
Is there a way to either have the same problem on localhost (the /public in the url) or is there an other easy fix? Cause right now if I fix my code on my online server, it doesn't work locally anymore and vise versa.
External CSS, Images and JS
Example Here,
Your URL Like:
For CSS
<link rel="stylesheet" type="text/css" href="{{url('/public/file_name.css')}}">
For JS
<script type="text/javascript" src="{{url('/public/file_name.js')}}">
After domain name, you must use public and then your CSS, images, and js path.

Laravel mix hot reload and domain name

I use Laravel Homestead for my development environment, so my website is accessible on http://test.app
Now I tried to configure laravel mix to use it with VUEJS. For this, I include a JS file in one of my templates:
<script src="{{ url(mix('js/main.js'))}}"></script>
The result of this is
<script src="//localhost:8080/js/main.js"></script>
It seems so, that the localhost:8080 is hardcoded in vendor/laravel/framework/src/Illuminate/Foundation/helper.php (see https://github.com/laravel/framework/blob/e35a60f7f3ef1d75754522771f13762b3058f1b0/src/Illuminate/Foundation/helpers.php#L560)
How to fix this or how I done something wrong?
the source you quote will only be executed in watch mode.
In this case, Laravel mix host a server on 8080 port for all your static files (css, js) so you can get the hot-reload feature, while the php files still running on your Homestead Niginx, and I don't see anything wrong with it.
it will compile to your APP_URL in production mode and if 8080 is somehow conflicting with your other service you can modify config file of Laravel Mix.
try setting APP_URL in your .env config file
APP_URL = http://test.app
i hope it helps.

Wrong Image, javascript url Path

I host Laravel project on xampp server. but now I run the laravel project using php artisan serve. When I run the artisan server, the url is http://localhost:8000. but my xampp server is http://localhost. The url path is wrong. The images doesn't appear and javascript and jquery don't work on my project. how can i fix it?
use this way to url CSS and JS files path
<link rel="stylesheet" href="{{ URL::asset('css/app.css') }}">
and image path use
<img src="{{url('/images'}}">
//here you have to give public path ex: in your public folder has images then use like this

How to change image path using htaccess?

I'm fixing this joomla site. It uses joomla 1.7 language filter so it adds post fixes to the url. So when i view an artcle with images, image is not displaying.
I tried htaccess rewrite rules. But it didn't work for me...
this is what i get when i copy image url.
http://domain.com/en/images/myimage.png
But when I check the code its images/myimage.png .
If i edit code to /images/myimage.png it works.
Tthis is what i try to do with htaccess too, to add a "/". Since it didn't work i guess i have to change whole url.
I don't have much knowledge in rewriting.
Can you guys help me please?
Give this a go in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^.*/images/(.*)$ http://%{HTTP_HOST}/images/$1 [L,R=301]
</IfModule>
This will rewrite your /en/images/... requests to /images/...
Note, this could have unexpected consequences for other URLs. I would suggest properly testing this on your own application.
The .htaccess solution only works partially for me, so I fixed this from the template's index.php file.
Inside the <head> tag, after the <jdoc:include type="head" /> code I added this code
<?php
//removed joomla autogenerated <base> tag
unset($doc->base); ?>
<base href="<?php echo JURI::root(); ?>">
Tested with Joomla 3.6.5

Resources