I'm trying to achieve two things within my Laravel 5.8 project:
First of all, add the next variable on my .env file:
FILESYSTEM_DRIVER=public
And finally, modify my public disk url from this:
'url' => env('APP_URL').'/storage',
To this:
'url' => env('APP_URL').'/api/storage',
Either way, it doesn't work. What am I doing wrong? Is it the .env variable or I can't do such thing as modify the disk url?
Yes you can. To modify the default file system, set the FILESYSTEM_DRIVER in your .env file:
.env
FILESYSTEM_DRIVER=public
Then in your config/filesystems.php, to modify the url do this:
config/filesystems.php
'disks' => [
...
'public' => [
...
'url' => env('APP_URL').'/api/storage',
...
],
...
],
Do not forget to clear your config cache after doing this changes:
php artisan config:clear
Related
How to disable cache in Laravel 8 for localserver? Its creating too much cache files. Its taking too much time to reflect changes.
To disable the cache you have to add the following to your config/cache.php file.
'stores' => [
//...
'none' => [
'driver' => 'null',
],
],
Now you have to change your CACHE_DRIVER value to none in your .env file and your cache is disabled.
You can do multiple things like:
CACHE_DRIVER=none
CACHE_EXPIRE=-1
and a command to clear view cache:
php artisan view:clear
In your .env file, set:
CACHE_DRIVER=array
Arrays are not persisted between requests.
I putted file on project-dir/client_secret_1***.apps.googleusercontent.com.json and then added variable into env file.
GOOGLE_PLAY_CREDENTIAL=http://local.project-dir/client_secret_1***.apps.googleusercontent.com.json
and then in config/services.php
return [
'google_play' => [
'credential' => env('GOOGLE_PLAY_CREDENTIAL'),
],
];
So now when I use it as like below
$client->setAuthConfig(config('services.google_play.credential'));
it is returning error which is
"file "http://local.project-dir/client_secret_1***.apps.googleusercontent.com.json" does not exist"
Can someone kindly guide me, where I am wrong so that I can fix the issue. I would like to appreciate.
Thanks
Use Laravel Storage.
Edit config/filesystems.php to create new disk:
'services' => [
'driver' => 'local',
'root' => storage_path('app/services'),
],
// ...
Put your .json file into %your_project_root%/storage/app/services/
Edit .env file:
GOOGLE_PLAY_CREDENTIAL=client_secret_1***.apps.googleusercontent.com.json
Change setAuthConfig param:
$client->setAuthConfig(Storage::disk('services')->get(config('services.google_play.credential')));
Test your storage using Tinker in console:
php artisan tinker
Storage::disk('services')->get(config('services.google_play.credential'));
I have a project in Laravel in which one of the sections uploads images to the server. Images are saved by using File storage and in the / storage/app/public folder.
In local it works correctly and the images look good, but when I upload the project to Heroku, the images are not seen. Even in Heroku if I run this command there are issues:
php artisan storage: link
Why is it that the images are not visible? I would not want to use AWS S3 for this. What could I have missed?
In your composer.json add:
"post-install-cmd": [
"ln -sr storage/app/public public/storage"
],
Heroku doesn't have file storage. So if you're going to use it for your servers you need to figure out another way to store files.
What I did that worked for me:
In your composer.json add:
"post-install-cmd": [ "ln -sr storage/app/public public/storage" ],( don't forget the comma , if you have any other line after the command above) But you should add the line above in scripts section.
Also, you need to run the command:
php artisan storage:link
Before running this command please check if the storage folder is already there or not inside the public folder if it's there then rename it to storage-bk and run the command. This way it creates new shortcut folder storage (storage/app/public).
This works for me:
You can add to your command line in your Procfile.
worker: php artisan storage:link
After adding this please push your project to Heroku again.
Also, you can upload images to the public folder instead using of a storage folder, by this method you will not get problems like the above.
for that, you need to change the config in app/filesystem.php
Change from:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Change into:
'public' => [
'driver' => 'local',
'root' => public_path(),
'url' => env('APP_URL').'/public',
'visibility' => 'public',
],
And you can store files so:
$pathToFile = Storage::disk('public')->put('uploads/', $file);
Now you can insert $pathToFile variable to the Database!
Having created a new user via Voyager, the avatar was showing as a broken image. I uploaded a new image, but the image remained broken.
I checked with Console in Google Chrome and found 3 404 errors:
2017-06-19 10:53:50.159
http://localhost:8888/storage/users/June2017/ypKlbqbATDbpnYctZBFp.png
Failed to load resource: the server responded with a status of 404
(Not Found)
2017-06-19 10:53:50.256
http://localhost:8888/storage/users/June2017/ypKlbqbATDbpnYctZBFp.png
Failed to load resource: the server responded with a status of 404
(Not Found)
2017-06-19 10:53:50.473
http://localhost:8888/vendor/tcg/voyager/assets/images/bg.jpg Failed
to load resource: the server responded with a status of 404 (Not
Found) When I looked at the project, the paths for the 2 storage
errors are: http://localhost:8888/storage/app/public/users/ and:
http://localhost:8888/storage/app/public/users/June2017
While in Media, I'm seeing similar path problems when navigating the folders:
2017-06-19 11:38:22.248 %7B%7B%20selected_file.path%20%7D%7D:1 GET
http://localhost:8888/development/PhpstormProjects/Search4Venues/public/admin/%7B%7B%20selected_file.path%20%7D%7D
404 (Not Found)
Anticipating the question, in .env, I have: APP_URL=http://localhost:8888
Is this a configuration error?
EDIT
A colleague with more experience than me has been through Voyager and found some inconsistencies, which he's attempted to fix.
In app.php, we've had to change:
'url' => env('APP_URL', 'http://localhost:8888/development/PhpstormProjects/Search4Venues'),
... to:
'url' => env('APP_URL', 'http://localhost:8888'),
In filesystems.php, we've had to change:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
... to:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/development/PhpstormProjects/Search4Venues/public/storage',
'visibility' => 'public',
]
However, he discovered other problems in config/voyager.php:
'assets_path' => '/vendor/tcg/voyager/assets',
... where it too appears to be missing PhpstormProjects/Search4Venues from the path:
http://localhost:8888/vendor/tcg/voyager/assets/images/bg.jpg
At this stage, we have no idea what else could be wrong with Voyager.
Firs u need edit file .env:
APP_URL=http://localhost
to:
APP_URL=http://yout-site-url
After that u need edit the file fylesystem.php like this:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/public/storage',
'visibility' => 'public',
],
I was helped
Follow these steps:
1.Change APP_URL in the .env file to your website url.
For example:
APP_URL=http://localhost
to
APP_URL=http://127.0.0.1:8000
2.Create symbolic link by: (if not done yet)
php artisan storge:link
3.Restart your server (must. Otherwise chages will not be applied.)
this is common problem that even official site of voyager is mention about just read this page https://voyager-docs.devdojo.com/troubleshooting/using-https
in summery just open file filesystem.php in the folder config and delete this line of code 'url' => env('APP_URL').'/storage',
Update you .env file
APP_URL=http://localhost:8000
and then run
php artisan config:clear
last
restart your serve
this work for me.
This error sometimes usualy shown if we runing php artisan serve with default port like localhost:8000, but if you place laravel wit voyager in htdocs/www in your own server like xampp/mamp etc this error will gone,
So you can try :
Installing apache or stand alone webserver like wamp or mamp
place your project in htdoc/www folder, and don't forget to set .env app_url:localhost (or your domain without port)
change document root in apache config to your project folder
acces http://[your_domain]/[your_project]
done..
thank's
Updated .env file:
APP_URL=http://localhost:8000
Fixed issue
dont forget to restart the server
Updated .env file:
APP_URL=http://localhost/voyager
And Updated filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage/app/public',
'visibility' => 'public',
],
All you need to do is change in .env
APP_URL = http://localhost
to
APP_URL = http://<whatever your site is called>
And then move to the pic files to
public users
For some reason voyager stores them in
public users\users
At least it did for me
Just check what URL Voyager creates for the avatars and move them into the public folder with the same URL.
Worked for me at least
Change one line in .env file:
APP_URL = http://localhost
to
APP_URL = http://<your site url>
The command is used to remove the configuration cache file and created again.
php artisan config:cache
if you using laragon, change
'url' => env('APP_URL').'/storage'
to
'url' => env('APP_URL').'./storage'
I have an image within the public/badges directory called 1.png - I am trying to use the Storage library in laravel but keep getting the following error even though the file does exist at that location:
// Error
FileNotFoundException in Filesystem.php line 381:
File not found at path: Users/gk/Sites/mysite/public/badges/1.png
// Code
$filePath = 'badges/1.png';
$path = public_path()."/".$filePath
Storage::disk('local')->get($path);
dd($contents);
Form Laravel 5.2 documentation:
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory.
So You are looking for file in: storage/app/Users/gk/Sites/mysite/public/badges/1.png
Error is quite confusing.
[Update]
Add to config/filesystems.php
'disks' => [
//...
'local_public' => [
'driver' => 'local',
'root' => public_path(),
],
//...
],
then
$filePath = 'badges/1.png';
$content = Storage::disk('local_public')->get($filePath);
dd($content);
I had the same problem in Laravel 5.7, this fix my problem:
php artisan storage:link