Tôi đang cố gắng gán user_id với người dùng hiện tại nhưng nó gây cho tôi lỗi này
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))
đây là phương pháp của tôi
//PostController
Post::create(request([
'body' => request('body'),
'title' => request('title'),
'user_id' => auth()->id()
]));
với những thứ này
//Post Model
protected $fillable = ['title', 'body', 'user_id']
Tuy nhiên, phương pháp này thực hiện công việc
//PostController
auth()->user()->publish(new Post(request(['title' ,'body'])));
//Post Model
public function publish(Post $post)
{
$this->posts()->save($post);
}
bất kỳ ý tưởng tại sao điều này không thành công?