AsArrayObject::class]; //------------------------------------------------------------ // -- RELATED TO RELATIONSHIP /// HAS ONE public function new_tv_request(): HasOne { return $this->hasOne(NewTvRequest::class, 'tv_fk', 'id'); } 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 RELATIONSHIP //------------------------------------------------------------ //------------------------------------------------------------ // -- RELATED TO DATA FUNCTION // -- END RELATED TO DATA FUNCTION //------------------------------------------------------------ //------------------------------------------------------------ // -- RELATED TO REQUEST public static function updateFromRequest(Request $request) { if($request->code) $request->merge(['code' => strtoupper($request->code)]); $request->validate([ 'id' => 'required|integer|exists:App\Models\Tv', 'code' => ['required','string',Rule::unique('tvs', 'code') ->when($request->id, function($q, $id) { $q->whereNot('id', $id); })], 'col1' => 'nullable|string', 'col2' => 'nullable|string', 'col3' => 'nullable|string', 'col4' => 'nullable|string', 'col5' => 'nullable|string', 'col6' => 'nullable|string', 'col7' => 'nullable|string', 'col8' => 'nullable|string', 'col9' => 'nullable|string', 'col10' => 'nullable|string', 'notes' => 'nullable|string', ]); try { DB::beginTransaction(); $tv = TV::findOrFail($request->id); $tv->code = $request->code; $tv->col1 = $request->col1; $tv->col2 = $request->col2; $tv->col3 = $request->col3; $tv->col4 = $request->col4; $tv->col5 = $request->col5; $tv->col6 = $request->col6; $tv->col7 = $request->col7; $tv->col8 = $request->col8; $tv->col9 = $request->col9; $tv->col10 = $request->col10; $tv->notes = $request->notes; $tv->update(); DB::commit(); return JSONResponse::Success(['message'=>'Success to update tv data']); // TODO: waiting from ops workflow // // try to sys_to_sys with indokargo // $jsonResponse = Indokargo::updateTVAddress($request, $tv->id, $tv->ik_address_id); // DB::commit(); // return $jsonResponse; } catch(\Throwable $th) { DB::rollback(); throw $th; } } public static function changeStatusFromRequest(Request $request) { $request->validate(['id' => 'required|integer|exists:App\Models\TV,id']); try { $tv = Tv::findOrFail($request->id); $tv->is_active = !$tv->is_active; $tv->save(); DB::commit(); return JSONResponse::Success(['message'=>'Success to change tv status']); // TODO: waiting from ops workflow // // try to sys_to_sys with indokargo // $jsonResponse = Indokargo::changeStatusAddress(new Request(['is_active' => $tv->is_active]), // $tv->id, $tv->ik_address_id); // DB::commit(); // return $jsonResponse; } catch(\Throwable $th) { DB::rollback(); throw $th; } } // -- END RELATED TO REQUES //------------------------------------------------------------ }