Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

serversideup/financial-freedom

2748 stars
2 code files
View serversideup/financial-freedom on GitHub

app/Models/Transactions/Transaction.php

Open in GitHub
use Illuminate\Database\Eloquent\Model;
 
class Transaction extends Model
{
//
public function accountable()
{
return $this->morphTo();
}
//
}

app/Services/Transactions/AddTransaction.php

Open in GitHub
use App\Models\Transactions\Transaction;
use App\Services\Tags\GetTag;
 
class AddTransaction
{
//
public function store()
{
$transaction = new Transaction();
 
$transaction->unique_id = uniqid();
$transaction->user_id = $this->user->id;
$transaction->accountable_id = $this->account->id;
$transaction->accountable_type = get_class( $this->account );
$transaction->amount = $this->amount;
$transaction->date = $this->date;
$transaction->name = $this->name;
$transaction->description = $this->description;
$transaction->direction = $this->direction;
$transaction->reconciled = 0;
 
$transaction->save();
 
$this->tagTransaction( $transaction );
 
return $transaction;
}
 
private function tagTransaction( $transaction )
{
if( $this->tags ){
$syncTags = [];
 
foreach( $this->tags as $submittedTag ){
$getTag = new GetTag( $submittedTag->name, $this->user );
$tag = $getTag->get();
 
array_push( $syncTags, $tag->id );
}
 
$transaction->tags()->sync( $syncTags );
}
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.