1. Go to this page and download the library: Download aw-studio/laravel-bitflags library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aw-studio / laravel-bitflags example snippets
class Email extends Model
{
// Email status flags, all powers of 2
public const SENT = 1;
public const RECEIVED = 2;
public const SEEN = 4;
public const READ = 8;
protected $fillable = ['status'];
public $casts = [
'status' => Bitflags::class
];
}
public function markRead()
{
$this->update([
'status' => addBitflag(self::READ, $this->status)
]);
}
public function scopeRead($query)
{
return $this->whereBitflag('status', self::READ);
}
public function scopeUnread($query)
{
return $this->whereBitflagNot('status', self::READ);
}
public function scopeSeenOrRead($query)
{
return $this->whereBitflagIn('status', [self::READ, self::SEEN]);
}
public function scopeSeenAndRead($query)
{
return $this->whereBitflags('status', [self::READ, self::SEEN]);
}
protected $appends = ['read'];
public function getReadAttribute()
{
return inBitmask(self::READ, $this->status);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.