• 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 connect to MSSQL Server with PHP from Ubuntu 18.04?

Distribute array row data to make multiple new rows

Sliders in Laravel

Check if user online laravel

Laravel multi auth - Authentication user provider [] is not defined

How to solve cURL error 60: SSL certificate in Laravel 5 while Facebook authentication

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

Laravel views are showing from cache on one server but works fine on other server

Pass an image through AJAX [duplicate]

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

laravel controller function parameters

How update php.ini on a Mac OS X Mojave?

Query Optimization, changing the queries in the loop into a single processing query

How to fix Call to undefined method AppModelsTableName::factory?

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

About Contact Privacy policy Terms and conditions