亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel“類名必須是有效的對象或字符串”

Laravel“類名必須是有效的對象或字符串”

PHP
回首憶惘然 2023-07-08 22:02:36
我想在我的 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')配置值將為空,并且您將收到所看到的錯誤。

查看完整回答
反對 回復 2023-07-08
?
呼如林

TA貢獻1798條經驗 獲得超3個贊

只需創建您的緩存

php artisan config:cache

composer dump-autoload


查看完整回答
反對 回復 2023-07-08
?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

對于像我這樣的新手,如果您在部署時遇到錯誤并且想知道如何刪除緩存中的配置,請執行以下操作;

sudo rm (YOUR PROJECT PATH HERE)/bootstrap/cache/config.php

在ubuntu服務器上


查看完整回答
反對 回復 2023-07-08
  • 3 回答
  • 0 關注
  • 227 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號