• 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

Spam Filter in Contact Form

Laravel Mix Uncaught ReferenceError: $ is not defined

"Unable to load dynamic library 'pdo_sqlsrv.so' "Cenos7 PHP7.2.10

Laravel MSSQL Server Connection not working

Why isn't my PHP exception working?

PDOException SQLSTATE[HY000] [2002] No such file or directory

PHP AWS Cognito 'Error executing "SignUp" : ResourceNotFoundException : User pool client XXXX does not exist

SQL AVG() to 2 decimals

Webscraping Symfony/Panther: Can't get HTML

find in set in laravel ? example

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

Xdebug in Laravel is not working with VSCode

What will the best solution for this multiple optional filter?

WordPress Security Standards want me to escape my html, but how to do it correctly?

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

About Contact Privacy policy Terms and conditions