我想在我的 Laravel 应用程序中的帖子后添加评论。我找到了我想使用的这个包https://github.com/laravelista/comments 。我安装了它,并按照说明进行操作,我现在遇到的问题是类名必须是有效的对象或字符串(查看:C:\xampp\htdocs\lsapp\resources\views\vendor\comments\components\comments.blade.php)它向我显示了这段代码: { return tap(new $class, function ($instance) { if (! $instance->getConnectionName()) { $instance->setConnection($this->connection); } }); }这段代码不是我写的,而是我安装前面提到的包后生成的。我的 Post.php 文件在这里:namespace TicketSystem;use Illuminate\Database\Eloquent\Model;use Laravelista\Comments\Commentable;class Post extends Model{ use Commentable; protected $table = 'posts'; //default? public $primaryKey = 'id'; public $timestamps = true; //default public function user() { return $this->belongsTo('TicketSystem\User'); }}我的 User.php 文件在这里:namespace TicketSystem;use Illuminate\Contracts\Auth\MustVerifyEmail;use Illuminate\Foundation\Auth\User as Authenticatable;use Illuminate\Notifications\Notifiable;use Illuminate\Contracts\Auth\CanResetPassword;use Laravelista\Comments\Commenter;class User extends Authenticatable{ use Notifiable, Commenter; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; public function posts() { return $this->hasMany('TicketSystem\Post'); }如何解决这个问题呢?我搜索了很多关于如何做的信息,但不是很成功。
3 回答

Cats萌萌
TA贡献1805条经验 获得超9个赞
我假设您的配置已缓存。重新缓存您的配置,它应该可以工作。
php artisan config:cache
该包有自己的配置文件,并使用该mergeConfigFrom()
方法。此方法在 Laravel 6.x 中更改为在缓存配置时不合并配置。
因此,如果您在安装此软件包时已经缓存了您的配置,则在安装软件包后重新缓存您的配置之前,将永远不会加载软件包配置。
由于未读取包配置,因此config('comments.model')
配置值将为空,并且您将收到所看到的错误。

翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
对于像我这样的新手,如果您在部署时遇到错误并且想知道如何删除缓存中的配置,请执行以下操作;
sudo rm (YOUR PROJECT PATH HERE)/bootstrap/cache/config.php
在ubuntu服务器上
没有找到匹配的内容?试试慕课网站内搜索吧
- 3 回答
- 0 关注
- 194 浏览
添加回答
举报
0/150
提交
取消