Just update your column-
$user->post_id = null;
Note: if you need to assign in DB, just update the column and make sure your column is nullable in DB.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
$user = new Post;
if ($user->type === "blue"){
if (DB::table('posts')
->where([
['type', '=', 'blue'],
['login_status', '=', 'no'],
]))
{
// How can assign null value for post_id
$user->post_id = ???;
}
else
{
$id = DB::table('posts')
->where([
['login_status', '=', 'yes'],
['type', '=', 'leaf'],
])
->first()
->id;
$user->post_id = $id;
}
}
$user->save();
I hope here is the solution that I can think of it for you...
$user = new Post;
//everything you need to add here as a new entry
// $user->post_id = null;
// $user->save()
$user = Post::find(pass a post id);
//now check whether post type == blue or not
if ($user->type == 'blue' AND $user->login_status == 'no'){
$user->post_id = null;
$user->save();
}
else {
$user->post_id = $id;
$user->save();
}
Please or to participate in this conversation.