%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/geotechnics/api/app/Models/
Upload File :
Create Path :
Current File : /var/www/html/geotechnics/api/app/Models/Device.php

<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;

/**
 * @property integer id
 * @property integer user_id
 * @property string uuid
 * @property string token
 * @property string language
 * @property string model
 * @property string platform
 * @property string version
 * @property string manufacturer
 * @property User user
 */
class Device extends BaseModel
{
    use Notifiable;

    const IOS = 'iOS';
    const ANDROID = 'Android';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'uuid',
        'token',
        'language',
        'model',
        'platform',
        'version',
        'user_id',
        'manufacturer',
    ];

    protected $guarded = [
        'user_id',
    ];

    protected $casts = [
        'uuid'         => 'string',
        'token'        => 'string',
        'language'     => 'string',
        'model'        => 'string',
        'platform'     => 'string',
        'version'      => 'string',
        'manufacturer' => 'string',
    ];

    public static function getDeviceByUUID($uuid)
    {
        return self::query()
                   ->where('uuid', $uuid)
                   ->first();
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Route notifications for the FCM channel.
     * @return string
     */
    public function routeNotificationForFcm()
    {
        return $this->token;
    }

    public function toggleConfiguration(Country $country)
    {
        /** @var NotificationConfiguration $config */
        $config = $this->configurations()
                       ->where('country_id', $country->id)
                       ->first();

        if ($config) {
            $config->delete();
        } else {
            $config = $this->configurations()
                           ->make([]);
            $config->country()
                   ->associate($country);
            $config->save();
        }
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function configurations()
    {
        return $this->hasMany(NotificationConfiguration::class);
    }

    public function enableConfiguration(Category $category)
    {
        /** @var NotificationConfiguration $config */
        $config = $this->configurations()
                       ->where('category_id', $category->id)
                       ->first();

        if (!$config) {
            $config = $this->configurations()
                           ->make([]);
        }

        $config->category()
               ->associate($category);
        $config->save();
    }

    public function disableConfiguration(Category $category)
    {
        /** @var NotificationConfiguration $config */
        $config = $this->configurations()
                       ->where('category_id', $category->id)
                       ->first();

        $config->delete();
    }

}



Zerion Mini Shell 1.0