• 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

Laravel after login Two factor not working

Valet, Xdebug after reboot Big Sur not working

MySQL order by field in Eloquent

how to sort by a custom appended relation to model

If you intend you use SMTP, add your SMTP Code after this Line

How to get monthly wise data in laravel

Insert a DIV after the 6th product only once in WooCommerce category archives

XML to CSV with PHP converter [problem with images grabing]

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

How can I pass the list to the component variable in Laravel?

Return new collection without modifying original collection

How to remove from a multidimensional array all duplicate elements including the original?

VichUploaderBundle error "Expected argument of type "File", "NULL" given" when submitting the form without selecting any file

php: command not found Command PhaseScriptExecution failed with a nonzero exit code

Which is faster php date functions or carbon?

About Contact Privacy policy Terms and conditions