I am trying to assign the user_id with the current user but it give me this error
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a
default value (SQL: insert into `posts` (`updated_at`, `created_at`)
values (2017-04-27 10:29:59, 2017-04-27 10:29:59))
here is my method
//PostController
Post::create(request([
'body' => request('body'),
'title' => request('title'),
'user_id' => auth()->id()
]));
with these fillables
//Post Model
protected $fillable = ['title', 'body', 'user_id']
However this method do the job
//PostController
auth()->user()->publish(new Post(request(['title' ,'body'])));
//Post Model
public function publish(Post $post)
{
$this->posts()->save($post);
}