Created
September 26, 2018 20:30
-
-
Save hmpmarketing/598c1ba8fbe26ff2fab787cdabfb1736 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use Illuminate\Database\Eloquent\Model; | |
class CampaignPlay extends Model | |
{ | |
public $primaryKey = false; | |
public $incrementing = false; | |
protected $guarded = []; | |
/** | |
* Get the campaign that owns the campaign_play. | |
*/ | |
public function campaign() | |
{ | |
return $this->belongsTo('App\Models\Campaign'); | |
} | |
public function scopeByCampaignId($query, $campaignId) | |
{ | |
return $query->where('campaign_id', '=', $campaignId); | |
} | |
public function scopeToday($query) | |
{ | |
return $query->where('campaign_date', '=', date('Y-m-d')); | |
} | |
public static function incrementPlayCount($campaignId) | |
{ | |
$count = self::byCampaignId($campaignId)->today()->increment('play_count'); | |
if ($count == 0) { | |
self::create([ | |
'campaign_id' => $campaignId, | |
'campaign_date' => date('Y-m-d'), | |
'play_count' => 1 | |
]); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment