• 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

How to KeyBy where multiple items have the same key

PHP SoapClient: set a namespace without prefix

PHP AWS Cognito 'Error executing "SignUp" : ResourceNotFoundException : User pool client XXXX does not exist

Component install error: JInstaller: :Install: File does not exist

CodeIgniter force_download is not working

How to change the app environment at run time?

How to use React Router with Laravel?

Magento Installation SQLSTATE[HY000] [2002] No such file or directory error

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

ConstraintViolationListInterface to Exception in Symfony

Remove country code from phone number?

SlimExceptionHttpNotFoundException

Override default Auth routes in Laravel 7

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

How to programmatically find public properties of a class from inside one of it's methods

About Contact Privacy policy Terms and conditions