I am developing an web application using Laravel 5 and AngularJS. I am using pure angularJS app for the client side and I am putting the client app files (views) in my public folder.
In Laravel 4, I could change the path from the bootstrap/start.php file. But in Laravel 5, I can not see the start.php file. So where do I change the configuration in Laravel 5?
See line 16 of config/view.php (the "View Storage Paths" section)
'paths' => [
realpath(base_path('resources/views'))
],
So you might change it to realpath(base_path('public/assets/views')) to be in your public path.
Additional Examples
'paths' => [
// src/MyNamespace/resources
realpath(base_path('src/MyNamespace/resources')),
// app/resources
realpath(app_path('resources'))
],
You can provide multiple search locations
You can use app_path(), base_path(), or neither.
Related
I'm putting my Laravel project in production and I've clone it from GitHub to /home/myuser/repositories/myuser/MYPROJECT-app, and my public Laravel folder content is in /home/myuser/public_html.
I've changed (project location)/app/Providers/AppServiceProvider.php and add:
$this->app->bind('path.public', function() {
return '/home/myuser/public_html';
});
To the Register function. I changed the index.php from the public folder to match my project location and everything works well, except when I try to upload a file using the method:
Storage::disk('public')->put('myfiles/', $request->myFile)
It is stored in /home/myuser/repositories/MYPROJECT-app/public/storage/myfiles instead of /home/myuser/public_html/storage/myfiles.
(Note: I cannot use symbolic links because some restrictions with the server configuration, so I'm trying to store all the files within a storage folder within the public path).
I'm guessing I'm missing some configuration to tell Laravel to store the uploaded files in /public_html/storage instead of MYPROJECT/public/storage, but I can't find which file I have to change.
This should work for you, but I cannot assure it 100%. (I will be using Laravel 9.x).
In your config/filesystems.php, go to the disks index and add a new one just for testing purposes:
'outside' => [
'driver' => 'local',
'root' => realpath('/home/myuser/public_html'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
As you can see, we are using realpath('/home/myuser/public_html'), but have in mind that url requires a symlink and you said it is not possible, so you are basically done there.
Let me know if this partially works, does it works but the URL not? Can you read files, store them, etc?
I have upgraded my Laravel 8 application to version 9, and according to the docs: upgrade guide, the resources/lang directory is now located in the root project directory (lang).
I've moved the lang directory to the root directory of my project, but it does not seem to work.
// config/app.php
'locale' => 'pt-BR',
and
// lang/pt-BR/messages.php
return [
'welcome' => 'Welcome to the app!',
];
Controller
return response()->json([
'message' => Lang::get('messages.welcome') // it returns "messages.welcome"
]);
But when I change the lang directory back to /resources/lang, it works fine like in previous laravel versions. So I created a new fresh project of Laravel 9, and it worked, which leads me to think that some additional configuration is needed, but it's not documented in the upgrade guide. My composer.json dependencies are precisely the same as the new laravel project. Is there any additional configuration that needs to be done for Laravel to recognize the directory?
So I found the solution, the "problem" was that I didn't removed the resources/lang directory so Laravel was using that directory instead of the lang directory in the base path of the application.
After removing the resources/lang directory it worked as expected. Thanks to #lagbox comment.
#IGP answer also worked.
You could hardcode your lang path using the useLangPath method in your AppServiceProvider's boot method.
# app/Providers/AppServiceProvider.php
public function boot()
{
app()->useLangPath(base_path('lang'));
// or app()->useLangPath(app()->basePath('lang'));
}
As per documentation you should use 'locale' => 'pt_BR' in config/app.php and name your lang folder lang/pt_BR/messages.php, (underscore) not pt-BR.
for languages that differ by territory, you should name the language directories according to the ISO 15897. For example, en_GB should be used for British English rather than en-gb.
I have an application that uses two different Laravel apps talking to the same database. App 1 is called BUILDER and App 2 is called VIEWER. In production I use S3 for storing files submitted within the application. For local development I use the storage/app/public folder in BUILDER.
The local dev setup is that BUILDER runs on localhost:8000 and VIEWER on locahost:8001
Now here comes my problem. In production both apps use the same S3 bucket for storage. So somehow I need to set this up similarly for local development.
The BUILDER is working fine, uploading and reading its files from the storage/app/public folder with FILESYSTEM_DRIVER=public in .env
The VIEWER is also reading these files fine, creating correct URL's after I added a new disk in the config (BUILDER_URL is set in .env to localhost:8000 which is the URL for the BUILDER)
'builder_public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('BUILDER_URL') . '/storage',
'visibility' => 'public',
],
BUT... I need to somehow be able to also upload files from the VIEWER app that should end up in the same storage folder as the BUILDER.
So in my VIEWER app I would like my builder_public disk to be something like this:
'builder_public' => [
'driver' => 'local',
'root' => builder_storage_path('app/public'), // here
'url' => env('BUILDER_URL') . '/storage',
'visibility' => 'public',
],
Is there some way I can share the storage/app folder between two separate Laravel apps?
Yes, you can. if you are using Linux server, try below command
ln -s SOURCE_FOLDER DESTINATION_FOLDER
it will create folder short cut but still, your both application will use the same location(DESTINATION_PATH)
If you are using different servers, try mount command.
I want to create a module (for example Users) in an advanced template application, that I could use it both in the backend (CRUD functionality) and frontend (login, profile)
Which is the right way of doing it, without having to create one module in backend and another in frontend and maybe a model in the common folder?
I want all files in one folder.
The simplest way for for create a module that you can use both backend and frontend and easily reusable also in other project is create the module in a your vendor dir eg:
vendor\yourvendorname\modulename\Module.php
then create the necessary dir
vendor\yourvendorname\modulename\controllers
vendor\yourvendorname\modulename\models
vendor\yourvendorname\modulename\views
the module name in module section config\main.php
'modules' => [
...
'modulename' => [ // dfenx module for migration via web without console command
'class' => 'vendor\youvendorname\yourmodulename\Module',
],
then refer to the module in you url eg:
yourprojectname/backend/web/index.php/modulename/controller
you can refer to this guide for tutorial
In my Laravel 5.1 app, I'm storing images in storage/app/uploads folder.
My local disk:
<?php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/uploads'),
],
// other configuration...
?>
Thing is, I can't figure out a way to use the image files after they're uploaded, e.g. as the source of <img> tag. Basically, I need to retrieve a valid path to an image, so it can be used on the page.
For deployment I'm using Envoyer which provides a solution. According to Envoyer docs:
When storing user uploaded files, you should store them in the storage directory of your application if you are using Laravel. Then, you may use the "Manage Linked Folders" feature of Envoyer to create a symbolic link from your public directory to the storage directory. The "Manage Linked Folders" button can be found on the "Deployment Hooks" tab of your project.
..and this is clear.
But how do I "link" the storage and public folders in my local development environment? Does Laravel provide a way to do it, or do I need to create a symbolic link in my environment manually?
There are a few options:
Create a controller that would output the files
class AssetController {
public function show($id) {
$file = File::findOrFail($id);
return Response::make(Storage::get($file->storage_key), 200, ['Content-Type' => $file->mime_type]);
}
}
Create a symlink public/assets => storage/app/
Upload files to public/assets instead of storage/app
Use rewrites on your web server to serve the files from your storage/app folder - how to do that depends on what webserver you are using. For nginx you could use something like
rewrite ^/v1/assets/(\d+) /../storage/app/$1;