 da195fd2fe
			
		
	
	
		da195fd2fe
		
			
		
	
	
	
	
		
			
			* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Requests\Api\Client\Servers\Databases;
 | |
| 
 | |
| use Webmozart\Assert\Assert;
 | |
| use App\Models\Server;
 | |
| use Illuminate\Validation\Rule;
 | |
| use App\Models\Database;
 | |
| use App\Models\Permission;
 | |
| use Illuminate\Database\Query\Builder;
 | |
| use App\Contracts\Http\ClientPermissionsRequest;
 | |
| use App\Http\Requests\Api\Client\ClientApiRequest;
 | |
| use App\Services\Databases\DatabaseManagementService;
 | |
| 
 | |
| class StoreDatabaseRequest extends ClientApiRequest implements ClientPermissionsRequest
 | |
| {
 | |
|     public function permission(): string
 | |
|     {
 | |
|         return Permission::ACTION_DATABASE_CREATE;
 | |
|     }
 | |
| 
 | |
|     public function rules(): array
 | |
|     {
 | |
|         $server = $this->route()->parameter('server');
 | |
| 
 | |
|         Assert::isInstanceOf($server, Server::class);
 | |
| 
 | |
|         return [
 | |
|             'database' => [
 | |
|                 'required',
 | |
|                 'alpha_dash',
 | |
|                 'min:3',
 | |
|                 'max:48',
 | |
|                 // Yes, I am aware that you could have the same database name across two unique hosts. However,
 | |
|                 // I don't really care about that for this validation. We just want to make sure it is unique to
 | |
|                 // the server itself. No need for complexity.
 | |
|                 Rule::unique('databases')->where(function (Builder $query) use ($server) {
 | |
|                     $query->where('server_id', $server->id)
 | |
|                         ->where('database', DatabaseManagementService::generateUniqueDatabaseName($this->input('database'), $server->id));
 | |
|                 }),
 | |
|             ],
 | |
|             'remote' => Database::getRulesForField('remote'),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @return array<array-key, string>
 | |
|      */
 | |
|     public function messages(): array
 | |
|     {
 | |
|         return [
 | |
|             'database.unique' => 'The database name you have selected is already in use by this server.',
 | |
|         ];
 | |
|     }
 | |
| }
 |