Comments & Discussion
THis has to be outdated with Laravel 10. Ive tried everything to get use Intervention\Image\Facades\Image recognized, and its just not working for the life of me.
Error: Class "Intervention\Image\Facades\Image" not found in /Applications/XAMPP/xamppfiles/htdocs/reservations/app/Http/Controllers/CompanyActivityController.php:105 This happens whenever I run my CompanyActivityTest.Test_can_upload_image wont pass because Image::make in the CompanyActivitiyController isn't recognized.
Ive tried adjusting providers array in app.php, as well as aliases, ive tried php artisan cache:clear, and config, tried php artisan optimize:clear, composer dump-autoload, verifiying its installed, reinstalling it, pretty much everything.
Well i think i finally solved it. I was installing intervention/image version 3.4. They totally changed how it works if you visit their Github (looking at the README.md: https://github.com/Intervention/image . So I looked at their revision history and tried using version 3.0 , still no dice. I then decided to use version 2.7. That fixed it, although i got a bunch of nasty warnings when i updated my composer.json intervention/image in "require" to 2.7. But that fixed it. I think the syntax might need updating to the modern version that Github reflects, however i could be wrong.
You are rigth. If you would look at the repository at the time of writing the 2.7 version was used. Maybe this course will get updated with the release of Laravel 11.
Anyone with php8.3 on Windows, did you managed to pass the "can upload test"? I didn't have imagick enabled, so I embarked on a quest to get it enable, and it looks like is not working with php 8.3 yet.
FAILED Tests\Feature\CompanyActivityTest > can upload image Unable to find a file or directory at path [thumbs/HQEcxv5QkPGmBwXYymJsmMrGSgYw5EIvWKq638wl.jpg]. Imagick PHP extension must be installed to use this driver.
at vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php:119 115▕ 116▕ $paths = Arr::wrap($path); 117▕ 118▕ foreach ($paths as $path) { ➜ 119▕ PHPUnit::assertTrue( 120▕ $this->exists($path), "Unable to find a file or directory at path [{$path}]." 121▕ ); 122▕ 123▕ if (! is_null($content)) {
1 vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php:119 2 tests\Feature\CompanyActivityTest.php:87
Tests: 1 failed, 13 passed (31 assertions) Duration: 4.25s
I do have php 8.1 installed, but since I started the tutorial with php 8.3 I can't switch back and forth. I'm curios if someone in my situation managed to move forward.
Thanks!
Can you expand on the part where I don't need to start over if I switch to php 8.1? I am interested to move forward without having write the whole thing from ground up, but when I tried to switch from php8.3 to php8.1, and atempted to run php artisan serve I had a different error requiring at least php 8.2. The Laravel version I'm using is 10.3.
Maan, this was a long journey. There is no official release of imagick for PHP 8.3 due to issues with the build machine (according to their statement on Github) however there are a few nice people that made it their mission to build imagick for PHP 8.3 and can be downloaded form here: https://github.com/Imagick/imagick/issues/573#issuecomment-1827616798 Now I have all test passing on Windows as well.
If have an issue displaying the thumbnails. I configured filesystems.php as in this lesson, but my files are getting stored in public/storage/activities instead of public/activities. For this reason the images don't show up.
I could fix this by changing the method to:
protected function thumbnail(): Attribute { return Attribute::make( get: fn () => $this->photo ? '/storage/activities/thumbs/' . $this->photo : '/noimage.png', ); }
Or by changing following in the the filesystems.php
'root' => storage_path('app/public/activities')
to
'root' => public_path() . '/activities',
- Could there be something wrong and is that the reason why it uses this subfolder storage?
- Which fix is the best? I see public_path() only stores the file in the public path in a none linked folder, but not in the storage folder.
You should not store images in the public folder. Your public folder should have a symlink called storage there (after running php artisan storage:link) and you should access all of your images from /storage/XXX/XXX.png.
Changing your filesystem to write to public path is really bad as that will push all images to GIT, which will cause issues.
I think that you are misunderstanding things a little bit :)
/public/storage will symlink to /storage/app/public - which means that all the uploads can be accessed publicly.
There's another, private storage, which would write into /storage/app and it would not be accessible via url. It will be uploaded, but there will not be any access from URL endpoint.
So to answer your question - you have to upload all your files to /storage/app/public which will be accessible via domain.com/storage/PATH_TO_FILE
I think we need to remove the image when deleting the activity
I suggest this in destroy method: