I want to change the public folder to public_html, the main problem is that some commands and functions not work because it still point to public.
I am trying to use the laravel+vue to develop a spa. i normally rename the public folder to public_html and that's all, but know it seems that i have to use the public_path helper and the console and these use the public folder too.
im using npm run dev as in the laravel docs, but it generate everything in the public folder, not in the public_html that i have renamed
so how can i tell the console and the public_path helper to do they magic in the public_html folder?
I am using Laravel 5.6, it is a fresh project, with just a controller and a view with a mix helper calling the js that i want link this <script src="{{ mix('js/app.js') }}"></script>.
May this can help you. You can override Laravel default helper methods. This code helped me at a time when I got same problem like you.
Simple I created one helper file and override public_html function something like this:
/**
* Get the path to the public folder.
*
* #param string $path
* #return string
*/
function public_path($path = '')
{
return base_path().'/public_html';
}
Let's say file name is AppHelper.php and located into app/Http folder.
To override helper from base you need to include your helper file(AppHelper.php) before Laravel does it's own autoload file.
So for the web you have to include your file into index.php like this:
require __DIR__.'/../app/Http/AppHelper.php';
require __DIR__.'/../vendor/autoload.php';
Remember your helper must be included before autoload file. and this code snippet for Command line or Artisan CLI:
require __DIR__.'/app/Http/AppHelper.php';
require __DIR__.'/vendor/autoload.php';
You have to write your artisan cli changes into artisan file which is on root.
In Laravel if you check helper function then each and every function wrapped with if condition like this function is not exist then declare it using function_exists()
In our case we already declare public_path function and included before Laravel autoload file so every request first execute our function.
Hope this can help you. Good luck.
Add this in register() method of your AppServiceProvider
public function register()
{
// Add this part
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
}
For the css+js resources, as #Bagus Tesa said, you have a file named webpack.mix.js in the root of your application folder. It's not you who created it, it comes with the laravel project. In that file you'll find something like:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Change the destination path from public to public_html
Related
I changed my laravel installation folder structure by moving all files and folders from the root directory to a new folder 'core'.
The goal is, to have only the folders in the root directory of the project
core
public
I have updated the index.php in public folder but I have the following problem:
when I die dump the paths, all are correct except the public path
dd(app_path()); // somepath\project\core\app
dd(storage_path()); // somepath\project\core\storage
dd(base_path()); // somepath\project\core
dd(public_path()); // somepath\project\core\public
I want to retain all other paths and change only the public path to somepath\project\public instead of somepath\project\core\public , how can I do this, online docs I've reference focus on changing public_html to public but I don't want to change the public_html, just to tell laravel that the public path is somepath\project\public
This particularly needful for me as I use the laravel storage for handling uploads.
Below is my folder structure
project
|-core
|- every other folders and files
|-public
|-every other asset files
You need to rewrite the base path in the app/Providers/AppServiceProvider.php like so:
public function boot()
{
$this->app->bind('path.public', function () {
return dirname(getcwd(), 1) . '/public';
});
}
Had this working but just updated my website on the server and it seems to have made all my uploaded files head to my public folder in my project rather than the public_html. Any idea on which file i must have uploaded and the fix?
You said you had it working before.
Was that on the same server...live?
If so, then could that be a server issue and not necessarily laravel issue?
Maybe you should ask your host for help and clarifications about what changed?
If you are convinced it was about what you changed...then care to show us?
Ideally if the server is cpanel, you will want to upload all your laravel files into your home's directly...then all your /public folder content into public_html
It will look like this:
.cpanel/
app/
etc/
bootstrap/
mail/
public_html/
content from your laravel /public directory
vendor/
...etc
You also need to go into your /public_html and edit the index.php content:
require __DIR__.’/../vendor/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And make sure it points to the correct location of your bootstrap folder..if you follow the structure above, then its ok.
Lastly, confirm that your PHP is indeed >= PHP7.0
With help from this answer: https://stackoverflow.com/a/50261573/3475551
I managed to get laravel to save uploaded files to my servers public directory instead of app/public.
Edit app/Providers/AppServiceProvider.php like this:
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../../public_html');
});
}
Hope this helps.
I have a helper.php file in app/Helpers directory. I included that file in composer.json:
...
"files": [
"app/Helpers/helpers.php"
]
...
Helper works fine but I can't use public_path() method there. I need to include another file (please don't ask me why because it's old code that I don't need to rewrite). So I have the following:
require_once public_path() . '/appadmin/bootstrap.php';
I know that by default Laravel looks in /public/ folder but I faced with a problem. If I need to perform composer update I have to use public/appadmin/bootstrap.php path in helper.php, but after performing I have to change that path to /appadmin/bootstrap.php for correct work. That's why I decide to use public_path() method to receive correct path for both cases. And if I use it I'm getting an error:
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
Script Illuminate\Foundation\ComposerScripts::postUpdate handling
the post-update-cmd event terminated with an exception
[ReflectionException]
Class path.public does not exist
Thank's in advance!
Have you tried updating your app to the current revision?
There are some files in the framework itself who need to be updated.
Check out the config files, the bootstrap files, server.php and the start files here https://github.com/laravel/laravel/tree/develop.
You could open index.php (in your public directory) and change:
$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Now you dont need to change your public path when your public directory has changed.
I am using laravel and deployed my application on server
application folder path /var/www/app
So when i run the url with public, css will load.
http://xxx.xxx.xxx.xxx/app/public/
But when i remove the public from url, css will not load.
http://xxx.xxx.xxx.xxx/app/
Css and js files are located into the public folder
How can i solve this issue, can i change the asset path if yes please tell me the where the asset define
Thanks
Laravel is designed to run the code from the public directory, so files like .env are protected from public access. Your server should be pointed to the public folder.
However, if you want to change the public url, you can edit the index.php file and specify your own path:
// add after $app = require_once... in index.php
$app->bind('path.public', function() {
return __DIR__;
});
I’m getting error when trying to autoload ion_auth library
application/config/autoload.php
$autoload['libraries'] = array('database', 'template', 'asset', 'ion_auth/ion_auth');
folder structure:
application/
...
modules/
ion_auth/
...
config/
ion_auth.php
...
tester/
controllers/
tester.php
I try to var_dump($this->ion_auth) on tester.php and get error message:
The configuration file ion_auth.php does not exist.
I try to $this->load->library('ion_auth/ion_auth') from tester.php and remove the ionauth from autoload, It still error. How to solve this?
I download codeigniter from link on codeigniter.com and download Modular Extension from bitbucket
It's not an issue with Modular Extensions. You need to put the config file for Ion Auth into the main application's config folder, not in the Ion Auth directory.
Just move it from application/modules/ion_auth/config/ion_auth.php to application/config/ion_auth.php. That will take care of the config error, but you'll probably need to move the entire Ion Auth library into application/libraries.
I don't use Modular Extensions, but from the looks of your code, I'd venture to guess that CI doesn't know to look in the ion_auth folder for the config folder.
If Modular Extensions has a config option, make sure to set it to look in the extension's folder for a config folder. If it doesn't, you'll need to either tell CI directly about the config folder, or put the ion_auth config file into a recognized config folder.
I'm doing exactly the same as you, HMVC from wiredesignz, CI and Ion_auth and I had the same problem. I solved it loading the config file PRIOR the library, :P, I don't know if this would be your problem, but I also had exactly the same error message. My construct method with Ion_auth looks like
class Auth extends MY_Controller {
function __construct()
{
parent::__construct();
// THIS LINE BEFORE LOAD THE LIBRARY:
$this->load->config('auth/ion_auth', TRUE);
$this->load->library('ion_auth');
$this->load->library('session');
$this->load->library('form_validation');
$this->form_validation->CI = & $this;
$this->load->database();
$this->load->helper('url');
$this->load->helper('cookie');
$this->load->library('email');
$this->load->library('session');
$this->lang->load('auth/ion_auth');
$this->load->model('auth/ion_auth_model');
}