• 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

Failing validation doesn't stop code execution in livewire component

Results page in other window

How to convert a carbon into string, to take the date only?

Get number of working days between two dates in PHP [duplicate]

"cannot list resources" error from WooCommerce REST API

Laravel get user data with profile

How to debug in WooCommerce 3+

Autoloading classes in PHPUnit using Composer and autoload.php

How do I remove this delivery notification from here?

carbon generated datetime not stored correctly into the database

How to unlink image from folder?

ConstraintViolationListInterface to Exception in Symfony

How to create custom authentication in laravel 8?

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

how do i retrieve and display the alt text of an image in wordpress?

About Contact Privacy policy Terms and conditions