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 //------------------------------------------------------------ }