Enjoy these free Code Nuggets?

Your support helps us create more high-quality content and unlocks exclusive premium nuggets via a personal activation link.

Support Our Work & Get Exclusive Access
🤖 New — AI Training

Learn to code with AI, not just about it.

Beyond free snippets, we run hands-on training in AI-assisted coding — teaching developers, teams and beginners how to build real software faster using modern AI tools. You bring the ideas; we show you how to ship them with an AI pair-programmer at your side.

  • ✔ Prompting & pairing with AI coding assistants to write, debug and refactor real code
  • ✔ Turning plain-English ideas into working apps, scripts and automations
  • ✔ Reviewing AI output safely — spotting bugs, security gaps and hallucinations
  • ✔ Live cohorts, team workshops and 1-on-1 mentoring — remote or on-site in Kenya
ai-pair-session.md

# You describe it…

"Build me a booking form that emails the client."

# …the AI drafts it…

▸ generating form + mailer…

â–¸ 24 lines written, 0 errors

# …and we teach you to lead it.

✱ You stay the engineer. AI is the tool.

Laravel nuggets

5 nuggets found

Clear filter

AfyaCore HMIS: Master Patient Index & FEFO Pharmacy Inventory Engine (Premium)

High-volume hospital EMR architecture combining longitudinal patient record indexing, FEFO (First Expired First Out) stock batch control, and M-Pesa/insurance billing reconciliation.Requires Premium Membership (KES 500/month) to unlock full database schema,...

// AfyaCore HMIS FEFO Stock Allocation Engine
namespace App\Services;

class PharmacyBatchService {
    public function allocateFEFOStock(int $itemId, int $requestedQty): array {
        $batches = StoreBatch::where('item_id', $itemId)
            ->where('quantity_remaining', '>', 0)
            ->...

Offloading Slow Work with Laravel Queues (Premium)

Sending email, resizing images or calling third-party APIs inside a web request makes users wait. Push that work onto a queue and the response returns instantly while a worker handles...

// app/Jobs/SendWelcomeEmail.php
class SendWelcomeEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(public User $user) {}

    public function handle(): void
    {
        Mail::to($this->user->email)->send(new Welc...

Validating Input Cleanly with Form Requests (Premium)

Stuffing validation rules into a controller makes it noisy. A Form Request moves rules, authorization and custom messages into their own class, and Laravel auto-validates before the controller method even...

// php artisan make:request StorePostRequest
class StorePostRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('create', Post::class);
    }

    public function rules(): array
    {
        return [
            'title' => ['required', 'string...

Shaping JSON Responses with Eloquent API Resources (Premium)

Returning a raw model leaks every column and couples your API to your schema. An API Resource is a transformation layer: you decide exactly which fields ship, rename them, and...

// php artisan make:resource PostResource
class PostResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'id'         => $this->id,
            'title'      => $this->title,
            'excerpt'    => Str::limit(strip_tags($this->body), 140...

Reusable Query Logic with Eloquent Scopes (Premium)

When the same where clauses appear all over your app, wrap them in a query scope. Scopes read like plain English and keep filtering rules in one place.

class Post extends Model
{
    // Local scopes: prefix with "scope"
    public function scopePublished($query)
    {
        return $query->whereNotNull('published_at')
                     ->where('published_at', '<=', now());
    }

    public function scopeSearch($query, ?string $term)
    {...