• 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 install php_imagick on wamp64

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

using random function but it's displaying duplicates

MySQL upgrade causing unexpected results on simple WHERE clauses

"There is no active transaction" when refreshing database in Laravel 8.0 test

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Form Validation and Submission to database

Search for array row with specific column value and return another value from qualifying row

Inserting data into SQL Server Db An Invalid direction was specified

How to find the date a user created their Google account

yii2 and mssql insert varbinary into model

Can we define variables in `.tpl` files?

Hide specific products from unlogged users based in product category in WooCommerce

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

How to use React Router with Laravel?

About Contact Privacy policy Terms and conditions