deletion improvement
This commit is contained in:
		@@ -4,10 +4,7 @@ namespace App\Http\Livewire\Source\Github;
 | 
			
		||||
 | 
			
		||||
use App\Models\GithubApp;
 | 
			
		||||
use App\Models\InstanceSettings;
 | 
			
		||||
use Illuminate\Support\Facades\Http;
 | 
			
		||||
use Illuminate\Support\Facades\Route;
 | 
			
		||||
use Livewire\Component;
 | 
			
		||||
use Illuminate\Support\Str;
 | 
			
		||||
 | 
			
		||||
class Change extends Component
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,15 @@ class GithubApp extends BaseModel
 | 
			
		||||
    protected $casts = [
 | 
			
		||||
        'is_public' => 'boolean',
 | 
			
		||||
    ];
 | 
			
		||||
    protected static function booted(): void
 | 
			
		||||
    {
 | 
			
		||||
        static::deleting(function (GithubApp $github_app) {
 | 
			
		||||
            $applications_count = Application::where('source_id', $github_app->id)->count();
 | 
			
		||||
            if ($applications_count > 0) {
 | 
			
		||||
                throw new \Exception('You cannot delete this GitHub App because it is in use by ' . $applications_count . ' application(s). Delete them first.');
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    public function applications()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->morphMany(Application::class, 'source');
 | 
			
		||||
 
 | 
			
		||||
@@ -78,6 +78,7 @@
 | 
			
		||||
            })
 | 
			
		||||
            Livewire.on('error', (message) => {
 | 
			
		||||
                console.log(message);
 | 
			
		||||
                alert(message);
 | 
			
		||||
            })
 | 
			
		||||
            Livewire.on('saved', (message) => {
 | 
			
		||||
                if (message) console.log(message);
 | 
			
		||||
 
 | 
			
		||||
@@ -64,5 +64,4 @@
 | 
			
		||||
            <x-inputs.button>Update Repositories</x-inputs.button>
 | 
			
		||||
        </a>
 | 
			
		||||
    @endif
 | 
			
		||||
 | 
			
		||||
</x-layout>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user