我想在我的 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');
}
如何解决这个问题呢?我搜索了很多关于如何做的信息,但不是很成功。
回首忆惘然
Cats萌萌
呼如林
翻翻过去那场雪
随时随地看视频慕课网APP