Fixed YABs, disk speed and network foreign key on delete issues

Fixed YABs, disk speed and network foreign key on delete issues
This commit is contained in:
cp6 2022-06-24 11:17:59 +10:00
parent 2f8db4ca24
commit ee73ea1a31
3 changed files with 25 additions and 9 deletions

View File

@ -133,16 +133,9 @@ class YabsController extends Controller
public function destroy(Yabs $yab)
{
$id = $yab->id;
$yabs = Yabs::find($id);
$yabs = Yabs::find($yab->id);
$yabs->delete();
$disk = DiskSpeed::find($id);
$disk->delete();
$network = NetworkSpeed::find($id);
$network->delete();
$update_server = DB::table('servers')
->where('id', $yab->server_id)
->update(['has_yabs' => 0]);

View File

@ -37,7 +37,7 @@ class AddForeignKeys extends Migration
});
Schema::table('yabs', function (Blueprint $table) {
$table->foreign('server_id', 'yabs_fk_servers')->references('id')->on('servers');
$table->foreign('server_id', 'yabs_fk_servers')->references('id')->on('servers')->onDelete('cascade');
});
Schema::table('disk_speed', function (Blueprint $table) {

View File

@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('disk_speed', function (Blueprint $table) {
$table->dropForeign('ds_fk_yabs');
$table->foreign('id', 'ds_fk_yabs')->references('id')->on('yabs')->onDelete('cascade');
});
Schema::table('network_speed', function (Blueprint $table) {
$table->dropForeign('ns_fk_yabs');
$table->foreign('id', 'ns_fk_yabs')->references('id')->on('yabs')->onDelete('cascade');
});
}
};