Advertisement
robbinhood_

Campaign

Jun 21st, 2021
3,870
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Models;
  4.  
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7.  
  8. class Campaign extends Model
  9. {
  10.     use HasFactory;
  11.  
  12.     /**
  13.      * fillable
  14.      *
  15.      * @var array
  16.      */
  17.     protected $fillable = [
  18.         'title', 'slug', 'category_id', 'target_donation', 'max_date', 'description', 'image', 'user_id'
  19.     ];
  20.  
  21.     /**
  22.      * category
  23.      *
  24.      * @return void
  25.      */
  26.     public function category()
  27.     {
  28.         return $this->belongsTo(Category::class);
  29.     }
  30.  
  31.     /**
  32.      * user
  33.      *
  34.      * @return void
  35.      */
  36.     public function user()
  37.     {
  38.         return $this->belongsTo(User::class);
  39.     }
  40.  
  41.     /**
  42.      * donations
  43.      *
  44.      * @return void
  45.      */
  46.     public function donations()
  47.     {
  48.         return $this->hasMany(Donation::class);
  49.     }
  50.  
  51.     /**
  52.      * sumDonation
  53.      *
  54.      * @return void
  55.      */
  56.     public function sumDonation()
  57.     {
  58.         return $this->hasMany(Donation::class)->selectRaw('donations.campaign_id,SUM(donations.amount) as total')->where('donations.status', 'success')->groupBy('donations.campaign_id');
  59.     }
  60.  
  61.     /**
  62.      * getImageAttribute
  63.      *
  64.      * @param  mixed $image
  65.      * @return void
  66.      */
  67.     public function getImageAttribute($image)
  68.     {
  69.         return asset('storage/campaigns/' . $image);
  70.     }
  71. }
  72.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement