pc_fuel
pc_fuel

Reputation: 786

Laravel 7- Getting public twice in the URL while using asset()

While using asset() to load a background image in a css stylesheet, I am getting an URL such as this

http://localhost/LaraTest/public/public/images/5copy.jpg

tThe public appears twice. But I want the URL like this http://localhost/LaraTest/public/images/5copy.jpg , i.e with only one public

Here are a few codes

CSS

background: url( '{{ asset('images/5copy.jpg') }}') no-repeat;

.env

ASSET_URL= http://localhost/LaraTest/public

config/app.php

'asset_url' => env('ASSET_URL','http://localhost/LaraTest/public'),

Where am I doing wrong?

Upvotes: 0

Views: 745

Answers (1)

Abilogos
Abilogos

Reputation: 5055

first you have to config your server for your web base url to be in public folder.

and you have not to include public in your url.

if you do that you dont need to config anything for asset url. and it should be like this:

'asset_url' => env('ASSET_URL', null),

You have to not include /public in any URL

/public is just a directory in your laravel project:

look at this nginx config

server {
    listen 80;
    server_name *.laravelproject.test
                 10.0.2.2
                 192.168.43.100;
    root /srv/www/htdocs/laravelProject/public;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;
    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    error_page 404 /index.php;
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    location ~ /\.(?!well-known).* {
        deny all;
    }
}

root directory is /srv/www/htdocs/laravelProject/public

Upvotes: 1

Related Questions