Advertisement
rzaglinskiy

Untitled

Jan 18th, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Models;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6. use Backpack\CRUD\CrudTrait;
  7.  
  8. class Subscriber extends Model
  9. {
  10.     use CrudTrait;
  11.     use \Venturecraft\Revisionable\RevisionableTrait;
  12.  
  13.     protected $table = 'subscribers';
  14.  
  15.     protected $primaryKey = 'id';
  16.  
  17.     public $timestamps = false;
  18.  
  19.     protected $dates = ['create_date'];
  20.  
  21.     protected $fillable = ['email', 'create_date', 'visibility', 'active', 'place', 'lon', 'lat'];
  22.  
  23.     protected $hidden = ['id'];
  24.  
  25.     public static function boot()
  26.     {
  27.         parent::boot();
  28.     }
  29.  
  30.     public function reports()
  31.     {
  32.         return $this->belongsToMany('App\Models\Report', 'report_subscribers', 'Subscribers_id', 'Report_id');
  33.     }
  34.  
  35.     public function category()
  36.     {
  37.         return $this->belongsToMany('App\Models\Category', 'subscriber_category', 'subscriber_id', 'category_id');
  38.     }
  39.  
  40. //    public function log(){
  41. //        return $this->belongsToMany('App\Models\Reportlog', 'report_log', 'subscriber_id', 'report_id');
  42. //    }
  43.  
  44.     public function logReport($report_id, $subscriber_id){
  45.         $time = time();
  46.         \DB::table('report_log')->insert(
  47.             [   'report_id' => $report_id,
  48.                 'subscriber_id' => $subscriber_id,
  49.                 'create_date'=>$time]
  50.         );
  51.     }
  52.  
  53.     public function setEmailAttribute($value){
  54.         $this->attributes['email'] = $value;
  55.         $this->attributes['create_date'] = time();
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement