Cannot find declaration to go to for assets - laravel

Most of my assets of my Laravel project are either in /storage folder or in the /public folder.
In my blade files, I references these asses with url('/storage/..). PhpStorm thinks that those do not exists.
When I commit, each image will add up to one error.
How can I tell PhpStorm that my assets are indeed in this directory?
I tried to add storage folder to PHP>Laravel>Views/Template but this doesn't work and I believe I have not fully understood what this path/namespace blade thing is supposed to do.

You could use the asset helper
style="background-image: url('{{ asset('storage/backgrounds/lavender') }}');">dfsdf</div>

do command this
php artisan storage:link
will create shortcut folder in public/storage to path storage/app/public
ineasted of url('/storage/..) to public_path('storage/....')

Related

laravel storage link not working on another system

I have an existing laravel project that I wrote on a Windows PC, I tried to copy the project to a MacBook and it runs well, but the problem is the storage:link doesn't work, all the picture I save in the storage folder can't be accessed through the app, I tried to enter the link of the files manually on the browser and it's still doesn't work.
I also checked the folder and the files, they still exist.
I'm still new in using Mac, does anyone have a solution?
I also tried to upload my laravel project to a shared hosting without SSH access, how can I make a storage link?
Thanks in advance.
I am not sure, maybe this is for wrong file locations. well, if you can find the folders you want to link you can run a raw command anyway
ln -s /project_folder/storage/app/public /project_folder/public/storage
Once you move the project to another system or directory , you need to recreate the symlink. Re run the command
php artisan storage:link
I'm using a shared hosting service and move everything in laravel's public directory into hosting's public_html and move everything beside laravel's public directory into a new folder I generate in the same directory as the public_html directory such as below:
root / parent directory
public_html
laravel
Make a file in public folder named symlink.php which contains this code:
<?php
$targetFolder = '../laravel/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage';
if(symlink($targetFolder,$linkFolder)){
echo 'Symlink completed';
} else {
echo 'Symlink Failed';
}
?>
you can specify the $targetFolder variable to your storage/app/public path like above.
afterwards call the file through your laravel link.
eg:
http://mylaravel-example.com/symlink.php
nb : the file's name is not a fixity, you can specify it as you desired.

LARAVEL 8 - I cannot view images from the Storage folder

sorry but I would need help with a project and I would be really grateful if you would help me.
The problem is that i cannot view the images from public/storage in a blade page.
To display the images I wrote:
<img class="card-img-top" src="{{ asset('storage/images/' . $category->image) }}" alt="">
To create the folder public/storage I used the command:
php artisan storage:link
I tried to delete and to recreate the folder but it still doesn't work
The path of images:
storage/app/public/images/
I'm so sorry for my english, I hope you understand the problem.
If you are a Linux user, then sometimes you need to give permission additionally to make it accessible. If you create your storage folder by the command php artisan storage:link and the storage folder has been corrupted, then delete the generated folder from public on the root and generate the shortcut by running the command again. Hopefully it will work.

laravel symlinks on a window machine

Using a windows server, I have a laravel installation.
I have a storage folder that I have created on 'root/storage'
When I save images from the website, the images are stored in this folder.
I use this to save the files:
Storage::disk('local')->put('course_badges/'.$pre_string . $request->file('badge')->getClientOriginalName(), File::get($request->file('badge')));
When I try to reference the file like so 'https://app.com/storage/file_name.jpg', laravel gives me a 'Sorry, the page you are looking for could not be found.' error.
However is I copy the files to '/public/storage/'
The image is then referenced correctly.
I have run the: php artisan symlink function.
I have tried to run ln -s ../storage/ command in powershell, but windows tells me that ln is not recognized.
What I am trying to achieve is to have my files saved in the root/storage folder (and sub folders)
and to reference them using https:app.nam/storage/file
I had simmilar issue
as u mentioned file is stored in root/storage means problem with symlink between root/storage to public/storage to fix this
remove storage folder from public dir
Note:- keep backup first
then run php artisan storage:link
it should work

Not Showing user avatar

HTML tag
<img src="storage/app/avatars/23_avatar1548246815.bmp" alt="">
File already exist on this path. But not showing.
And I used also this php artisan storage:link, but not working.
Error is Server Error 403 Forbidden.
According to laravel documentation.
The Public Disk
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.
To create the symbolic link, you may use the storage:link Artisan command:
php artisan storage:link
Of course, once a file has been stored and the symbolic link has been created, you can create a URL to the files using the asset helper:
echo asset('storage/file.txt');
thing I would do is definitely use this method
<img src="{{asset('assets/images/image.png')}}">
to link to your asset files.
Shouldnt the storage/app/avatars be storage/app/pubic/avatars ?
If you say that the file exists on that path, it points that the problem is with file permissions. Change the /project/storage permissions to 777, delete the public/storage folder, and run php artisan storage:link, then try one more time. If no, try to give 777 permissions to public folder

Laravel Symbolic Link not working

I have some problems creating a symbolic link with laravel to access files that are in my storage
I am storing my files in
storage\app\public
I used the php artisan command to create the link
php artisan storage: link
The [public/storage] directory has been linked.
Earlier files were storing in storage\app\public and were also visible in public\storage folder
But now they are only storing in storage\app\public and not visible in public\storage folder
I am using link to show file path
{{ Storage::url($package->reportPath['path']) }}
Path is showing correct but it redirect to 404 page as there is no file I guess.
This solved it for me on laravel 8, hosted on a ec2 server.
rm public/storage
php artisan optimize:clear
php artisan storage:link
Try removing your public/storage directory and try running storage:link again. This worked for me.
If you are trying to Show the stored file use asset()
asset('storage/further_path/').$file_name;
To store file you can do
$destinationPath = storage_path('app/public/further_path');
if (!is_dir($destinationPath)) {
mkdir($destinationPath, 0777, TRUE);
}
$request->file->move($destinationPath,$filename);
Hope this Helps You.
Let me Know if You have any problem.

Resources