• 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

Toggle between a textbox and a select using PHP

Laravel UUID generation

protect images from being copied

Laravel Database Strict Mode

Webscraping Symfony/Panther: Can't get HTML

How can I resolve "Your requirements could not be resolved to an installable set of packages" error?

Laravel 5.5 change unauthenticated login redirect url

Clear javascript source cache laravel 5.8

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

How to install php yaml on CentOs?

printing all running session variable in laravel 5.1

Laravel 8: Array to string conversion while calling route:list

Warning: sqlite_query() expects parameter 1 to be resource, string given

How to Create WooCommerce Subscription Product via. REST API?

How to get Laravel's CSRF Token from Another Website?

About Contact Privacy policy Terms and conditions