I want to install laravel in shared hosting and I followed the steps here https://stackoverflow.com/a/28449523 but my asset path doesn't include the public directory
Instead of this
<link href='http://example.com/public/assets/css/style.css' type='text/css' media='all' />
I'm getting this
<link href='http://example.com/assets/css/style.css' type='text/css' media='all' />
How do I change the directory of the asset folder(add public to assets) without changing any core classes?
This is a typical Laravel folder structure, with the default public folder : / /app /bootstrap /config /database /public /index.php /resources /routes /storage. This is specially useful when you try to deploy or publish your application in a standard web server.
Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.
Add ASSET_URL=public in your .env file and run php artisan config:cache
For the latest version of Laravel - Laravel 5.8, there is a key in config/app.php with name asset_url. The value of this key determines the value that the asset() method returns. Normally, you should set the value of this key to the base url of your website if all your asset folders are in the default location (this default location is the public folder under the root directory of your Laravel installation).
For example if your website url is "https://www.example.com" and you want to access the asset path public/assets/css/sample.css under the root folder, set the asset_url in config/app.php like this:
'asset_url' => env('ASSET_URL', 'https://www.example.com'),
and use the asset function like this:
asset('assets/css/sample.css')
Thereafter, reconfigure your cache by running this within your laravel installation folder:
php artisan config:cache
This will update the bootstrap/cache/config.php file. If you check your browser, the generated url for your asset would be "https://www.example.com/assets/css/sample.css".
One way you can have a valid url like: "https://www.example.com/public/assets/css/sample.css" is by creating another folder named public inside your already existing public folder - which is non-intuitive for me. However, if you do this, then you have to include this path when using the asset function:
asset('public/assets/css/sample.css')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With