Laravel没有创建特定模型的对象

时间:2015-12-22 01:29:08

标签: php laravel eloquent laravel-5.1

我有一个Model Comment.php和DB上的表注释。

我有一些能够在该表中插入数据的播种机以及一系列其他模型和控制器已经正常工作。

问题是每当我试图创建一个新的评论时,它就会变空。例如:

    {
    $comment = new Comment([
        'description' => $request->input('description'),
        'status' => 'active',
        'profile_id' => $request->input('profile_id')
    ]);

    return $comment;
    }

返回

[]

我确保模型和控制器都存在。我实际上可以索引所有评论。我也在使用正确的模型:

use App\Comment;

任何想法我应该在哪里检查或为什么Laravel / Eloquent在尝试创建新对象时没有识别模型?

编辑:

这是我的模特:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
public $fillable = ['*'];

public function profile(){
    $this->belongsTo(Profile::class);
}

public function project(){
    $this->belongsTo(Project::class);
}

public function scopeOfProject($query,$projectId){
    return $query->where('project_id',$projectId);
}

1 个答案:

答案 0 :(得分:1)

public $fillable = ['*'];

是问题。