Compare commits

...

1 Commits

@ -14,9 +14,9 @@ class TvAppInfo extends Model {
public $incrementing = false;
//------------------------------------------------------------
// -- RELATED TO MIGRATION
// -- RELATED TO RELATIONSHIP
/// BELONGS TO
public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); }
// -- END RELATED TO MIGRATION
// -- END RELATED TO RELATIONSHIP
//------------------------------------------------------------
}

@ -10,9 +10,9 @@ class TvConnectLog extends Model {
use HasFactory;
//------------------------------------------------------------
// -- RELATED TO MIGRATION
// -- RELATED TO RELATIONSHIP
/// BELONGS TO
public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); }
// -- END RELATED TO MIGRATION
// -- END RELATED TO RELATIONSHIP
//------------------------------------------------------------
}

@ -10,9 +10,9 @@ class TvSession extends Model {
use HasFactory;
//------------------------------------------------------------
// -- RELATED TO MIGRATION
// -- RELATED TO RELATIONSHIP
/// BELONGS TO
public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); }
// -- END RELATED TO MIGRATION
// -- END RELATED TO RELATIONSHIP
//------------------------------------------------------------
}

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NewTvRequest extends Model {
use HasFactory;
protected $table = 'new_tv_requests';
}

@ -2,11 +2,14 @@
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;
@ -25,4 +28,40 @@ class Tv extends Model {
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
//------------------------------------------------------------
}

@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
@ -16,7 +15,6 @@ return new class extends Migration
$table->string('code', 50)->unique();
$table->string('ik_address_id', 255);
$table->string('notes', 255)->nullable();
$table->timestampTz('last_connected_at')->nullable();
$table->string('col1', 255)->nullable();
$table->string('col2', 255)->nullable();
$table->string('col3', 255)->nullable();
@ -27,53 +25,65 @@ return new class extends Migration
$table->string('col8', 255)->nullable();
$table->string('col9', 255)->nullable();
$table->string('col10', 255)->nullable();
$table->bool('is_acctive')->default(true);
$table->boolean('is_active')->default(true);
$table->timestampTz('installed_at')->nullable();
$table->timestampTz('last_connected_at')->nullable();
$table->timestampsTz();
});
Schema::create('tv_sessions', function (Blueprint $table) {
Schema::create('new_tv_requests', function (Blueprint $table) {
$table->id();
$table->foreignId('tv_fk')->index();
$table->timestampTz('started_at')->index();
$table->timestampTz('finished_at')->nullable()->index();
$table->boolean('is_playing_video');
$table->jsonb('current_videos')->nullable();
$table->string('code', 50);
$table->jsonb('device_info')->nullable();
$table->timestampTz('activated_at')->nullable();
$table->timestampTz('responded_at')->nullable();
$table->timestampsTz();
$table->foreign('tv_fk')->references('id')->on('tvs');
});
Schema::create('tv_app_infos', function (Blueprint $table) {
$table->foreignId('tv_fk')->unique()->index();
$table->timestampTz('installed_at')->nullable()->index();
$table->jsonb('current_videos')->nullable();
$table->timestampTz('last_updated_video')->nullable()->index();
$table->timestampsTz();
// Schema::create('tv_sessions', function (Blueprint $table) {
// $table->id();
// $table->foreignId('tv_fk')->index();
// $table->timestampTz('started_at')->index();
// $table->timestampTz('finished_at')->nullable()->index();
// $table->boolean('is_playing_video');
// $table->jsonb('current_videos')->nullable();
// $table->timestampsTz();
$table->foreign('tv_fk')->references('id')->on('tvs');
});
// $table->foreign('tv_fk')->references('id')->on('tvs');
// });
Schema::create('tv_app_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('tv_fk')->index();
$table->string('requested_to');
$table->string('ip', 50);
$table->jsonb('request_data')->nullable();
$table->enum('result', ['success', 'failed']);
$table->jsonb('response_data')->nullable();
$table->timestampsTz();
// Schema::create('tv_app_infos', function (Blueprint $table) {
// $table->foreignId('tv_fk')->unique()->index();
// $table->timestampTz('installed_at')->nullable()->index();
// $table->jsonb('current_videos')->nullable();
// $table->timestampTz('last_updated_video')->nullable()->index();
// $table->timestampsTz();
$table->foreign('tv_fk')->references('id')->on('tvs');
});
// $table->foreign('tv_fk')->references('id')->on('tvs');
// });
// Schema::create('tv_app_logs', function (Blueprint $table) {
// $table->id();
// $table->foreignId('tv_fk')->index();
// $table->string('requested_to');
// $table->string('ip', 50);
// $table->jsonb('request_data')->nullable();
// $table->enum('result', ['success', 'failed']);
// $table->jsonb('response_data')->nullable();
// $table->timestampsTz();
// $table->foreign('tv_fk')->references('id')->on('tvs');
// });
}
/**
* Reverse the migrations.
*/
public function down(): void {
Schema::drop('tv_app_logs');
Schema::drop('tv_app_infos');
Schema::drop('tv_sessions');
// Schema::drop('tv_app_logs');
// Schema::drop('tv_app_infos');
// Schema::drop('tv_sessions');
Schema::drop('new_tv_requests');
Schema::drop('tvs');
}
};

Loading…
Cancel
Save