In this tutorial we will see how to use boolean value in laravel 9. Boolean value are 0,1 and true, false, For this section we will create blog post crud and add status in boolean value.

there are multiple way we can store boolean value like using checked box, radio button we will see both.

app/Http/Controllers/BlogController.php validate($request, [ 'title' => 'required|string|max:255', 'content' => 'required' ]); $blog = Blog::create([ 'title' => $request->title, 'content' => $request->content, 'status' => $request->status == 'on' ?

* * @param \Illuminate\Http\Request $request * @param \App\Models\Blog $blog * @return \Illuminate\Http\Response */ public function update(Request $request, Blog $blog) { $request->validate([ 'title' => 'required|string|max:255', 'content' => 'required', 'status' => 'required|boolean:0,1,true,false' ]); $blog->update([ 'title' => $request->title, 'content' => $request->content, 'status' => $request->status ]); return redirect()->route('blogs.index'); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Community Partners