On the Post model:
public function status()
{
return $this->hasOne('App\Models\Status');
}
On the Status model:
public function post()
{
return $this->belongsTo('App\Models\Post');
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I was able to get this answer from 3 years ago: https://laracasts.com/discuss/channels/laravel/how-would-you-make-a-draft-feature
So if I set up a new "status" column on my "posts" table, does this column have to be of boolean type and be set to null? Do I need a pivoting table, how do I keep a post from being rendered just by checking if the status is set to 1 or 0? So if its 1, the post should be hidden or if its set to 0, it should not be hidden.
This is how I think the relationship looks:
The way im managing this on my CRUD view is by rendering a list of all posts, I can delete or update but I do want to have a "Draft" list so i can continue the writing using a button or an <a>, should I have a function that looks for any post whos status is set to 1?
public function store(Request $request)
{
$this->validatePost();
$post = new Post(request(['title', 'body', 'slug', 'status']));
if($post->status = true) {
// write on the column
// hide the post from being published
// continue with the request
}
$post->user_id = 1;
$post->tags()->attach(request('tags'));
return redirect('/posts');
}
protected function validatePost()
{
return request()->validate([
'title' => 'required|max:255',
'body' => 'required',
'slug' => 'required|max:100',
'tags' => 'exists:tags,id',
'status' => 'required'
]);
}
Im looking to have a basic setup here, as a first approach to the idea.
Please or to participate in this conversation.