abivia / ledger

General Ledger and Journal Accounting Package and API for Laravel
MIT License
102 stars 23 forks source link

Multitenancy Support #19

Closed marvoh closed 5 months ago

marvoh commented 5 months ago

Hello,

Thank you for your wonderful work. I am trying to integrate it into a multitenant set-up through Filament V3 where a Ledger would belong to a company.

I have extended the LedgerName model to add the relationship to the company as follows:

<?php

namespace App\Models\Ledger;

use Abivia\Ledger\Models\LedgerName;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Wallo\FilamentCompanies\FilamentCompanies;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Ledger extends LedgerName  {

    use SoftDeletes;
    protected $table = 'ledger_names';
    public function company(): BelongsTo
    {
        return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
    }

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
    }

    public function updatedBy(): BelongsTo
    {
        return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
    }
}

I am looking for a best practise recommendation being new to Laravel while also trying to avoid redoing most of the work which the API already has done when persisting the relationships such as currency, accounts etc.

Best, N