• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Passing a boolean value from checkbox in Laravel form

phplaravel


PHP Snippet 1:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $casts = [
        'is_featured' => 'boolean',
        'is_place' => 'boolean',
    ];
}

PHP Snippet 2:

<input type="checkbox" name="is_featured" class="switch-input" value="1" {{ old('is_featured') ? 'checked="checked"' : '' }}/>

PHP Snippet 3:

$post->is_featured = $request->has('is_featured');

Related Snippets

Ajax GET request fails in laravel 8

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

MongoDB Duplicate Documents even after adding unique key

How to create custom authentication in laravel 8?

Laravel get user data with profile

PHP mail function is sending blank message body

Laravel: HTML in notification

Add bold text and line break into Laravel Notification Email

How do I truncate a decimal in PHP?

Create a new line whenever an array value reaches more than 10 characters

PHP using str_starts_with for array to exclude same as with wildcard

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

Prevent blank space in pdf pages (DomPdf)

Limit of log line written to Apache Errorlog from mod php error_log

Split a string array into pieces

About Contact Privacy policy Terms and conditions