You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Helper\JSONResponse;
|
|
use AWS\CRT\HTTP\Request;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Tv extends Model {
|
|
use HasFactory;
|
|
|
|
protected $table = 'tvs';
|
|
protected $hidden = ['ik_cust_id', 'ik_address_id'];
|
|
|
|
//------------------------------------------------------------
|
|
// -- RELATED TO MIGRATION
|
|
/// HAS ONE
|
|
public function tv_app_info(): HasOne { return $this->hasOne(TvAppInfo::class, 'tv_fk', 'id'); }
|
|
/// HAS MANY
|
|
public function tv_connect_logs(): HasMany { return $this->hasMany(TvConnectLog::class, 'tv_fk', 'id'); }
|
|
public function tv_sessions(): HasMany { return $this->hasMany(TvSession::class, 'tv_fk', 'id'); }
|
|
/// BELONGS TO
|
|
public function outlet(): BelongsTo { return $this->belongsTo(Outlet::class, 'outlet_fk', 'id'); }
|
|
// -- END RELATED TO MIGRATION
|
|
//------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------
|
|
// -- RELATED TO DATA FUNCTION
|
|
public static function generateRandomCode(): string {
|
|
$totalDigit = 6;
|
|
$randomDigit = '';
|
|
while(true) {
|
|
$randomDigit = strtoupper(Str::random($totalDigit));
|
|
$isExist = Tv::where('code', $randomDigit)->first();
|
|
if(!$isExist) break;
|
|
}
|
|
return $randomDigit;
|
|
}
|
|
// -- END RELATED TO DATA FUNCTION
|
|
//------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------
|
|
// -- RELATED TO DATA FUNCTION
|
|
public static function createAnonymousData() :Tv {
|
|
$newTv = new self;
|
|
$newTv->code = self::generateRandomCode();
|
|
$newTv->is_active = true;
|
|
$newTv->save();
|
|
return $newTv;
|
|
}
|
|
// -- END RELATED TO DATA FUNCTION
|
|
//------------------------------------------------------------
|
|
|
|
|
|
//------------------------------------------------------------
|
|
// -- RELATED TO REQUEST
|
|
public static function renewTvInformation(Request $request) {
|
|
|
|
}
|
|
// -- END RELATED TO REQUEST
|
|
//------------------------------------------------------------
|
|
}
|