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

<?php
namespace App\Models\Concerns;

use App\Models\Organization;
use Illuminate\Database\Eloquent\Builder;

trait BelongsToOrganization
{
    protected static function bootBelongsToOrganization(): void
    {
        // Applies only during web requests where the middleware bound an org.
        // Console commands and queue jobs run unscoped.
        static::addGlobalScope('org', function (Builder $q) {
            if (app()->bound('currentOrg')) {
                $q->where($q->getModel()->getTable() . '.organization_id', app('currentOrg')->id);
            }
        });

        static::creating(function ($m) {
            if (!$m->organization_id && app()->bound('currentOrg')) {
                $m->organization_id = app('currentOrg')->id;
            }
        });
    }

    public function organization() { return $this->belongsTo(Organization::class); }
}

Add use BelongsToOrganization; to Post, SocialAccount, and Media. In User.php add:

php
public function organizations() { return $this->belongsToMany(Organization::class)->withPivot('role'); }
