Project.php 2.38 KB
Newer Older
beardedwarrior's avatar
beardedwarrior committed
1 2 3 4 5
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
6
use SimpleSoftwareIO\QrCode\Facades\QrCode;
beardedwarrior's avatar
beardedwarrior committed
7

8
/**
9
 * App\ProjectResource
10 11 12 13 14 15 16 17 18
 *
 * @property int $id
 * @property string $payment_id
 * @property string $target_amount
 * @property string $status
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Deposit[] $deposits
 * @property-read mixed $amount_received
beardedwarrior's avatar
beardedwarrior committed
19
 * @property-read string $uri
20 21
 * @property-read int $percentage_funded
 * @property-read int $contributions
22
 * @property-read string $qrcode
23 24 25 26 27 28 29
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project wherePaymentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereTargetAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereUpdatedAt($value)
 * @mixin \Eloquent
30 31 32 33 34 35
 * @property string $title
 * @property int|null $merge_request_id
 * @property string|null $commit_sha
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereCommitSha($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereMergeRequestId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereTitle($value)
36
 */
beardedwarrior's avatar
beardedwarrior committed
37 38
class Project extends Model
{
39
    protected $guarded = ['id'];
beardedwarrior's avatar
beardedwarrior committed
40 41 42 43 44
    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function deposits()
    {
45
        return $this->hasMany(Deposit::class, 'payment_id', 'payment_id');
beardedwarrior's avatar
beardedwarrior committed
46
    }
47 48 49 50

    public function getAmountReceivedAttribute() {
        return $this->deposits->sum('amount');
    }
beardedwarrior's avatar
beardedwarrior committed
51 52 53 54

    public function getUriAttribute() {
        return 'monero:'.env('WALLET_ADDRESS').'tx_payment_id='.$this->payment_id;
    }
55 56 57 58 59 60 61 62 63

    public function getPercentageFundedAttribute() {
        return round($this->amount_received / $this->target_amount * 100);
    }

    public function getContributionsAttribute() {
        return $this->deposits->count() ?? 0;
    }

64
    public function getQrcodeAttribute() {
65 66
        return QrCode::format('png')->size(500)->generate($this->uri);
    }
beardedwarrior's avatar
beardedwarrior committed
67
}