• Czas czytania ~ :czas min
  • 08.11.2022

Laravel Flagi modeli to pakiet firmy Spatie, który umożliwia dodawanie flag do modelu Eloquent:

use Illuminate\Database\Eloquent\Model;
use Spatie\ModelFlags\Models\Concerns\HasFlags;
 
class User extends Model
{
    use HasFlags;
}
User::notFlagged('wasSentPromotionMail')
    ->each(function(User $user) {
        Mail::to($user->email)->send(new PromotionMail())
 
        $user->flag('wasSentPromotionMail');
    });
});
$user->hasFlag('someExperimentalFeature'); // returns bool
 
// Flag the user for someExperimentalFeature
$user->flag('someExperimentalFeature');
 
// Now the flag returns true
$user->hasFlag('someExperimentalFeature');
 
// Get all users with the flag
User::flagged('someExperimentalFeature')->get();
 
// Get all users without the flag
User::notFlagged('someExperimentalFeature')->get();

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

O

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

O autorze CrazyBoy49z
WORK EXPERIENCE
Kontakt
Ukraine, Lutsk
+380979856297