Laravel 5 change public_path()
You can override the public path using ioc container :
What worked for me flawlessly was adding to public/index.php
the following three lines:
$app->bind('path.public', function() {
return __DIR__;
});
For more detailed explanation click here
Laravel 5 on shared hosting - wrong public_path()
You can override public_path using container.
Example:
App::bind('path.public', function() {
return base_path().'/public_html';
});
Alternate function of public_path() in laravel 8
You can modify register()
method on AppServiceProvider
:
public function register()
{
$this->app->bind('path.public', function() {
return base_path('../public_html'); // you given path from root
});
}
How to change public folder to public_html in laravel 5
Quite easy to find this with a simple search.
See: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5
In your index.php add the following 3 lines.
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Edit:
As Burak Erdem mentioned, another option (and more preferable) is to put this in the \App\Providers\AppServiceProvider
register()
method.
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// ...
$this->app->bind('path.public', function() {
return base_path('public_html');
});
}
How to change public folder to public_html in laravel 8?
You have to follow 2 steps to change your application's public folder to public_html then your can deploy it or anything you can do :)
Edit
\App\Providers\AppServiceProvider
register() method & add this code .// set the public path to this directory
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});Open
server.php
you can see this codeif ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
Just Replace it with :
if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
return false;
}
require_once __DIR__.'/public_html/index.php';
Then serve your application with php artisan serve
, you also can deploy it on your Cpanel shared hosting where primary document root public_html
Laravel Route Parameters change public_path
Either add /
to the beginning of the src
or use url()
(or asset()
).
src="/vendor/jquery/jquery-3.1.1.min.js"
or
src="{{ url('vendor/jquery/jquery-3.1.1.min.js') }}"
Just FYI, you wouldn't use public_path
as it would give you the fully qualified path in your file system not a url.
Hope this helps!
Related Topics
Executing MySQLi_Query Inside a Function
Jquery Ajax Settimeout After Form Succes Not Redirecting
How to Access the PHP.Ini File in Godaddy Shared Hosting Linux
How to Limit File Upload Type File Size in PHP
How to Get the Total Number of Rows of a Group by Query
How to Enable PHP's Openssl Extension to Install Composer
Laravel Eloquent Sum of Relation's Column
How to Convert String to Boolean PHP
Cloudflare and Logging Visitor Ip Addresses via in PHP
Custom Pagination View in Laravel 5
Php: Check If a File Is Loaded Directly Instead of Including
Performance of Try-Catch in PHP
Pkill -F Doesn't Work for Process Killing
How to Prevent PHP Sessions Being Shared Between Different Apache Vhosts