Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LARAVEL Argument 1 passed to ... Must be of the type array, int given

Tags:

php

laravel

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.

like image 740
beat Avatar asked Sep 17 '25 04:09

beat


1 Answers

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

like image 54
Salman Zafar Avatar answered Sep 18 '25 22:09

Salman Zafar