vendredi 22 juillet 2016

MassAssignmentException in Laravel 5.2 with fillable set up in Model

Yes, I know that this question was asked million times and I've read half of the answers. But still cannot get rid of the exception. Show me where I am wrong.

This is my model:

namespace App;
use Illuminate\Database\Eloquent\Model;
class Topic extends BaseModel
{
protected $primaryKey = 'id';
protected $table = 'topics';
protected $fillable = array('title', 'number', 'subjectid','content','imageid','created_at_ip', 'updated_at_ip');
}

This is the method in Controller that causes the exception:

public function store()
{
    //here are my variables definitions
    $topic = $this->request->except('_token'); // Exclude _token attribute
    $topic=Topic::create([
        'title'=>$title,
        'number'=>$number,
        'subjectid'=>$subjectid,
        'content'=>$content,
        'imageid'=>'1']
    );

    return view('addtopic', ['topic' => $topic , 'subjects' => $subjects ,'page'=>'topic', 'pagetitle'=>$pagetitle]);
}

I use $request as a property in my Controller and initiate it through constructor.

And this is the Exception:

MassAssignmentException in Model.php line 452:
title
in Model.php line 452
at Model->fill(array('title' => 'Create application 555', 'number' => '', 'subjectid' => '27', 'content' => 'imageid imageid', 'imageid' => '1')) in Model.php line 288
at Model->__construct(array('title' => 'Create application 555', 'number' => '',
'subjectid' => '27', 'content' => 'imageid imageid', 'imageid' => '1')) in Model.php line 572
at Model::create(array('title' => 'Create application 555', 'number' => '', 
TopicController.php line 83
at TopicController->store()



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire