php class name must be a valid object or a string
Laravel «Class name must be a valid object or a string»
I wanted to add comments after posts in my laravel app. I found this package https://github.com/laravelista/comments which i wanted to use. I installed it, and followed the instructions, the issue that i get now is
Class name must be a valid object or a string (View: C:\xampp\htdocs\lsapp\resources\views\vendor\comments\components\comments.blade.php)
and it shows me this code:
this code was not written by me, but generated after I installed the previously mentioned package.
My Post.php file is here:
and my User.php file is here:
in the blade.php file where I wanted to add comments:
how to solve this problem? I searched a lot on how to but it wasn’t very successful.
EDIT: comments.php file:
In PostsController file:
2 Answers 2
I’m assuming your config is cached. Re-cache your config and it should work.
This package has its own config file, and uses the mergeConfigFrom() method. This method was changed in Laravel 6.x to not merge configs when the config is cached.
So, if your config is already cached when you install this package, the package configuration will never be loaded until you re-cache your config after installing the package.
My Laravel application is throwing the next error:
I have to said that right now this project is in a shared hosting but that’s the only part that does not works at all. This is the HTML file:
And this is my controller:
Why does my code works perfectly while developing in my machine but it does not while hosted? I was looking online for a solution but everything i got was related with Entrust which i am not using at all. Any idea?
This is the whole error:
2 Answers 2
It seems that you are using Spatie/Laravel-permission, and if your app is working on development server, I guess that php version in your live server is less than 7.0 which is required by this package.
You should check your working php version using phpinfo(); on a file and pointing your browser to that file, this will show which php version is used by your webserver. eg: you can write down a file info.php with the following content
As noted by @erubiel and @farid-silva, you may need to address the PHP version on production.
However, the most proximate issue is that Spatie\Permission\Traits\HasRoles::roles calls Illuminate\Database\Eloquent\Concerns\HasRelationships::morphToMany with:
If you take a look at the code, these values are sourced from the Laravel configuration, namely:
so it might be worth sanity checking your configuration, namely the permission set of values, to check if these are properly defined on production.
Yii Framework
Выдает ошибку Class name must be a valid object or a string
Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:15
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:19
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение ElisDN » 2016.12.16, 19:19
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:31
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение zelenin » 2016.12.16, 19:34
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение ElisDN » 2016.12.16, 19:34
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:36
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение zelenin » 2016.12.16, 19:45
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:47
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение zelenin » 2016.12.16, 19:48
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:50
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение zelenin » 2016.12.16, 19:55
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 19:57
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение zelenin » 2016.12.16, 20:04
если напрямую в коде прописать?
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 20:15
если напрямую в коде прописать?
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение zelenin » 2016.12.16, 20:23
в общем проблема явно в какой-то мелочи типа опечатки или недосмотре.
xdebug’ом уже бы все продебажили.
Re: Выдает ошибку Class name must be a valid object or a string
Сообщение webplus » 2016.12.16, 20:26
php artisan app:update PHP Fatal error: Uncaught Error: Class name must be a valid object or a string in #2710
Comments
nixmomo commented Sep 12, 2017 •
after git checkout to the new 2.4 Branch i get this composer error
PHP Version 7.1
Waiting for a fix or to know what i should do to fix it
`Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 47 installs, 51 updates, 9 removals
1.1)
phpunit/phpunit suggests installing ext-xdebug ()
lcobucci/jwt suggests installing mdanter/ecc (Required to use Elliptic Curves based algorithms.)
filp/whoops suggests installing whoops/soap (Formats errors as SOAP responses)
Package graham-campbell/core is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postUpdate
php artisan optimize
PHP Fatal error: Uncaught Error: Class name must be a valid object or a string in /var/www/vhosts/censored/Cachet/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:96
Stack trace:
#0 [internal function]: Illuminate\Foundation\Exceptions\Handler->Illuminate\Foundation\Exceptions(0, ‘Illuminate\Http. ‘)
#1 /var/www/vhosts/censored/Cachet/bootstrap/cache/compiled.php(6449): call_user_func(Object(Closure), 0, ‘Illuminate\Http. ‘)
#2 /var/www/vhosts/censored/Cachet/bootstrap/cache/compiled.php(12660): Illuminate\Support\Arr::first(Array, Object(Closure), NULL)
#3 /var/www/vhosts/censored/Cachet/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(97): Illuminate\Support\Collection->first(Object(Closure))
#4 /var/www/vhosts/censored/Cachet/vendor/graham-campbell/exceptions/src/ExceptionHandlerTrait.php(40): Illuminate\Foundation\Exceptions\Handler->shouldn in /var/www/vhosts/censored/Cachet/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 96
PHP Fatal error: Uncaught Error: Class name must be a valid object or a string in /var/www/vhosts/censored/Cachet/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:96
Stack trace:
#0 [internal function]: Illuminate\Foundation\Exceptions\Handler->Illuminate\Foundation\Exceptions(0, ‘Illuminate\Http. ‘)
#1 /var/www/vhosts/censored/Cachet/bootstrap/cache/compiled.php(6449): call_user_func(Object(Closure), 0, ‘Illuminate\Http. ‘)
#2 /var/www/vhosts/censored/Cachet/bootstrap/cache/compiled.php(12660): Illuminate\Support\Arr::first(Array, Object(Closure), NULL)
#3 /var/www/vhosts/censored/Cachet/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(97): Illuminate\Support\Collection->first(Object(Closure))
#4 /var/www/vhosts/censored/Cachet/vendor/graham-campbell/exceptions/src/ExceptionHandlerTrait.php(40): Illuminate\Foundation\Exceptions\Handler->shouldn in /var/www/vhosts/censored/Cachet/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 96
`
The text was updated successfully, but these errors were encountered: