Laravel 5 Change Public_Path()

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 :)


  1. 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';
    });
  2. Open server.php you can see this code

    if ($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



Leave a reply



Submit