Laravel not creating objects of specific Model

- 1 answer

Ad

I have a Model Comment.php and the table comments on the DB.

I have some seeders that are able to insert data in that table and a bunch of other models and controllers already working.

The problem is that whenever im trying to create a new Comment it comes empty. For example:

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

    return $comment;
    }

returns

[]

I made sure the Model and the Controller both exists. I can actually index all the comments. I am also using the right Model:

use App\Comment;

Any idea where should I check or why does Laravel/Eloquent is not recognizing the model when trying to create a new object?

Edit:

This is my Model:

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);
}
Ad

Answer

Ad
public $fillable = ['*'];

Was the problem.

Ad
source: stackoverflow.com
Ad