I am trying to store an entry into a database but I get this error.
" Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, int given, called in C:\xampp\htdocs\im-stuff\test\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 869 "
request()->validate(['description' => 'required']);
$project->addTask(compact('description'));
Ok, so this does work, but next and better version doesn't.
$attributes = request()->validate(['description' => 'required']);
$project->addTask($attributes);
So this is the model which is being used.
public function tasks()
{
return $this->hasMany(Task::class);
}
public function addTask($description)
{
$this->tasks()->create(compact('description'));
}
At this point I am lost and really don't understand.
why are you using compact
when you are saving the record to database instead as i mentioned in my comment it should be like this simple and easy:
public function addTask($description)
{
$this->tasks()->create($description);
}
here you can find the working of compact
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With