Source path: app/Models/Organization.php
Extracted from supplied specification. Review before copying into application.

<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Organization extends Model
{
    protected $guarded = [];

    public function members()     { return $this->belongsToMany(User::class)->withPivot('role'); }
    public function aiProviders() { return $this->hasMany(OrgAiProvider::class); }

    public function spend(int $n): bool
    {
        return (bool) static::whereKey($this->id)->where('ai_credits', '>=', $n)->decrement('ai_credits', $n);
    }

    public function refund(int $n): void { static::whereKey($this->id)->increment('ai_credits', $n); }
}
