Laravel 7 : Interface 'Spatie\MediaLibrary\HasMedia' not found - laravel

I have this error while using the MediaLibrary package
Interface 'Spatie\MediaLibrary\HasMedia' not found
Trait 'Spatie\MediaLibrary\InteractsWithMedia' not found
My project details :-
php : 7.3.22
laravel : 7.28.3
I have tried follow the documentation v7 and also run the command below
composer require spatie/laravel-medialibrary
Other than that, I have also checked on other post which I have follow most of the steps but still getting back the same error
composer.json
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0",
"laravelcollective/html": "^6.2",
"spatie/laravel-activitylog": "^3.16",
"spatie/laravel-medialibrary": "^7.19"
},
Model
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Applicant extends Model implements HasMedia
{
use LogsActivity, InteractsWithMedia;
}

Make sure to follow the documentation for the specific version of Laravel-medialibrary that you are using. In your case version 7. It looks like you were following the version 8 documentation.
In version 7, the trait is Spatie\MediaLibrary\HasMedia\HasMediaTrait instead of Spatie\MediaLibrary\InteractsWithMedia. And the interface is Spatie\MediaLibrary\HasMedia\HasMedia instead of Spatie\MediaLibrary\HasMedia.
If you want to use version 8 instead, change your requirements to "spatie/laravel-medialibrary": "^8.0" and then run composer update.

Related

DOMPDF Failed to load PDF document on server (production)

I am using laravel 8 and have installed dompdf on MAMP and everything works fine, but as soon i deployed it to my production server dompdf does not work anymore.
I get the following message: Failed to load PDF document.
When I check the server logs i only a see 500 error without any additional details.
Is there anyone who has had the same issue?
I am using Laravel 8.12 with php 7.3.27 with dompdf
"barryvdh/laravel-dompdf": "^0.9.0",
This is the code I use:
$pdf = PDF::loadView('pdf.letters', ['batch' => $batch]);
return $pdf->stream('document.pdf');
I have checked and made sure:
MBString extension is enabled
DOM extension
I don't load in any custom fonts.
What I have tried:
Downgrading from dompdf 0.9.0 to 0.8.0
List item
Apache log returns no additional information only a 500 error.
Laravel log returns the following:
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy6039f3cdd6edf5.34383100.html' '/tmp/knp_snappy6039f3cdd702b5.29005326.pdf'. at /var/www/vhosts/domain.com/httpdocs/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php:381)
This my composer.json :
"require": {
"php": "^7.3|^8.0",
"barryvdh/laravel-dompdf": "^0.8.3",
"barryvdh/laravel-snappy": "^0.4.8",
"carlos-meneses/laravel-mpdf": "^2.1",
"darryldecode/cart": "^4.2",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"gladcodes/keygen": "^1.1",
"guzzlehttp/guzzle": "^7.0.1",
"h4cc/wkhtmltopdf-i386": "0.12.x",
"intervention/image": "^2.5",
"knplabs/knp-snappy": "^1.2",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5",
"laravelcollective/html": "^6.2",
"mollie/laravel-mollie": "^2.0",
"picqer/php-barcode-generator": "^2.1",
"spatie/laravel-medialibrary": "^7.0.0",
"stripe/stripe-php": "^7.74"
},
Thank you.

why does View::make() not exist in laravel docs?

why does View::make() not exist in laravel docs?
I have gone through on xVersion/views pages of all versions of Laravel docs, but I couldn't find any statement about View::make(). who can explain to me how it works?
additional info, I'm learning Aimeos Laravel package.
I don't think View::make is from Aimeos packages.
because, I see
composer.json
> "require": {
> "php": "^7.2.5",
> "aimeos/aimeos-laravel": "dev-master",
> "fideloper/proxy": "^4.2",
> "fruitcake/laravel-cors": "^2.0",
> "guzzlehttp/guzzle": "^6.3",
> "laravel/framework": "^7.24",
> "laravel/tinker": "^2.0",
> "laravel/ui": "^2.4"
> },
Many things in Laravel have multiple ways of referencing them.
The documentation prefers the use of the cleaner, less verbose view() helper, but you can use View::make if you prefer.
The API docs for View::make are at https://laravel.com/api/8.x/Illuminate/Contracts/View/Factory.html#method_make.
View::make is calling a make method on the View facade. This was how views were referenced in Laravel 4.x, but Laravel 5.x introduced the global view helper that does the same thing, just with a few less keystrokes.
Therefore, View::make('shop::page.privacy') is the same as view('shop::page.privacy').

Lumen first install - ReflectionException: Class redis does not exist

I am playing around with Lumen, I installed it via Lumen installer. After I do composer install, I try to use artisan but it throws the following error:
ReflectionException: Class redis does not exist in Container.php on line 752
My composer.json:
"require": {
"php": ">=7",
"ext-pdo_pgsql": "*",
"ext-soap": "*",
"guzzlehttp/guzzle": "^6.3",
"laravel/lumen-framework": "5.5.*",
"laravel/tinker": "^1.0",
"vlucas/phpdotenv": "~2.2"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.4",
"doctrine/dbal": "^2.5"
},
Thanks in advance.
I had the same.
Solution:
composer require illuminate/redis
Register it in bootstrap/app.php by calling
$app->register(Illuminate\Redis\RedisServiceProvider::class);
in the file, under Register Service Providers.
From this aricle.
From Lumen's official documentation at https://lumen.laravel.com/docs/7.x/cache :
Redis Support:
Before using a Redis cache with Lumen, you will need to install the illuminate/redis package via Composer. Then, you should register the Illuminate\Redis\RedisServiceProvider in your bootstrap/app.php file:
$app->register(Illuminate\Redis\RedisServiceProvider::class);
If you have not called $app->withEloquent() in your bootstrap/app.php file, then you should call $app->configure('database'); in the bootstrap/app.php file to ensure the Redis database configuration is properly loaded.

Laravel: PHP Fileinfo extension to use Intervention Image message

Hi on my localhost i can upload images perfect with Image Intervention. On my server i can't the say: Fileinfo extension must be installed/enabled to use Intervention Image. I change my PHP Version to 5.3.29 before are in 5.6. I enable File Info but still not working. After upload i delete vendor and i run
composer install
and
composer dump-autoload
and later i upload it to my server but the problem continues.
Here my composer.json file:
"require": {
"php": ">=5.3",
"laravel/framework": "5.2.*",
"laravelcollective/html":"*",
"laracasts/flash": "^2.0",
"cviebrock/eloquent-sluggable": "^4.0",
"intervention/image": "^2.3",
"laravel/socialite": "^2.0",
"cviebrock/image-validator": "^2.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
Some one can help me here? Thanks :)

How to get list of all installed packages along with version in composer?

I have been working on a project using Symfony 2.1 on my local machine. I have uploaded it to my server but when I try and install the vendor bundles using Composer, I'm getting a lot of dependency errors. Presumably this is something to do with the latest version of Symfony just being released and my composer.json file not specifying exact version numbers.
Is there any way I can quickly display the version numbers of everything on my local machine?
Here is my composer.json file (which worked fine until a few days ago):
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"sonata-project/admin-bundle": "*",
"sonata-project/cache-bundle": "dev-master",
"sonata-project/doctrine-orm-admin-bundle": "dev-master",
"stof/doctrine-extensions-bundle": "1.1.x-dev",
"sonata-project/user-bundle": "dev-master",
"sonata-project/easy-extends-bundle": "dev-master",
"friendsofsymfony/user-bundle": "2.0.x-dev",
"friendsofsymfony/jsrouting-bundle": "*",
"liip/imagine-bundle": "*",
"simplethings/form-extra-bundle": "dev-master",
"antimattr/google-bundle": "dev-master",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"genemu/form-bundle": "2.1.*",
"behat/behat": "2.4.*#stable",
"behat/mink": "1.4.*#stable",
"behat/symfony2-extension": "*#stable",
"behat/mink-extension": "*#stable",
"behat/mink-selenium2-driver": "*#stable",
"behat/mink-browserkit-driver": "*",
"liip/functional-test-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"minimum-stability": "dev",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web"
},
"config": {
"bin-dir": "bin/"
}
}
You can run composer show -i (short for --installed).
In the latest version just use composer show.
The -i options has been deprecated.
You can also use the global instalation of composer: composer global show
To list the globally installed composer packages:
composer global show -i
List installed dependencies:
Flat: composer show -i
Tree: composer show -i -t
-i short for --installed.
-t short for --tree.
ref: https://getcomposer.org/doc/03-cli.md#show
If you only want to check version for only one, you can do
composer show -- twig/twig
Note that only installed packages are shown by default now, and installed option is now deprecated.
The behaviour of this command as been modified so you don't have to pass the -i option:
[10:19:05] coil#coil:~/workspace/api$ composer show -i
You are using the deprecated option "installed".
Only installed packages are shown by default now.
The --all option can be used to show all packages.
Ivan's answer above is good:
composer global show -i
Added info: if you get a message somewhat like:
Composer could not find a composer.json file in ~/.composer
...you might have no packages installed yet. If so, you can ignore the next part of the message containing:
... please create a composer.json file ...
...as once you install a package the message will go away.
With composer-runtime-api 2.0+ there is a new InstalledVersions class with some static methods to see things programmatically.
For example:
// To list all packages (`string[]`)
\Composer\InstalledVersions::getInstalledPackages();
// To list every details of every packages
\Composer\InstalledVersions::getAllRawData();
More information: https://getcomposer.org/doc/07-runtime.md#installed-versions
If you want to install Symfony2.2, you can see the complete change in your composer.json on the Symfony blog.
Just update your file according to that and run composer update after that. That will install all new dependencies and Symfony2.2 on your project.
If you don't want to update to Symfony2.2, but have dependency errors, you should post these, so we can help you further.
Is there a way to get it via $event->getComposer()->getRepositoryManager()->getAllPackages()

Resources