diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 97407644..ffa6856b 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Configuration; use App\Models\Product; use Exception; use Illuminate\Contracts\Foundation\Application; @@ -51,6 +52,7 @@ class ProductController extends Controller "swap" => "required|numeric|max:1000000|min:0", "description" => "required|string|max:191", "disk" => "required|numeric|max:1000000|min:5", + "minimum_credits" => "required|numeric|max:1000000|min:-1", "io" => "required|numeric|max:1000000|min:0", "databases" => "required|numeric|max:1000000|min:0", "backups" => "required|numeric|max:1000000|min:0", @@ -73,7 +75,8 @@ class ProductController extends Controller public function show(Product $product) { return view('admin.products.show', [ - 'product' => $product + 'product' => $product, + 'minimum_credits' => Configuration::getValueByKey("MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER"), ]); } @@ -108,6 +111,7 @@ class ProductController extends Controller "description" => "required|string|max:191", "disk" => "required|numeric|max:1000000|min:5", "io" => "required|numeric|max:1000000|min:0", + "minimum_credits" => "required|numeric|max:1000000|min:-1", "databases" => "required|numeric|max:1000000|min:0", "backups" => "required|numeric|max:1000000|min:0", "allocations" => "required|numeric|max:1000000|min:0", @@ -125,7 +129,8 @@ class ProductController extends Controller * @param Product $product * @return RedirectResponse */ - public function disable(Request $request, Product $product) { + public function disable(Request $request, Product $product) + { $product->update(['disabled' => !$product->disabled]); return redirect()->route('admin.products.index')->with('success', 'product has been updated!'); @@ -181,12 +186,11 @@ class ProductController extends Controller ' . csrf_field() . ' ' . method_field("PATCH") . '
- - + +
'; - }) ->editColumn('created_at', function (Product $product) { return $product->created_at ? $product->created_at->diffForHumans() : ''; diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index f916c52c..d1c260cd 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -16,7 +16,8 @@ use Illuminate\Http\Client\Response; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; - +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Request as FacadesRequest; class ServerController extends Controller { @@ -39,6 +40,7 @@ class ServerController extends Controller $query->where('disabled', '=', false); })->get(), 'nests' => Nest::where('disabled', '=', false)->get(), + 'minimum_credits' => Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50) ]); } @@ -52,7 +54,7 @@ class ServerController extends Controller "description" => "nullable|max:191", "node_id" => "required|exists:nodes,id", "egg_id" => "required|exists:eggs,id", - "product_id" => "required|exists:products,id", + "product_id" => "required|exists:products,id" ]); //get required resources @@ -74,8 +76,8 @@ class ServerController extends Controller 'identifier' => $response->json()['attributes']['identifier'] ]); - if (Configuration::getValueByKey('SERVER_CREATE_CHARGE_FIRST_HOUR' , 'true') == 'true'){ - if (Auth::user()->credits >= $server->product->getHourlyPrice()){ + if (Configuration::getValueByKey('SERVER_CREATE_CHARGE_FIRST_HOUR', 'true') == 'true') { + if (Auth::user()->credits >= $server->product->getHourlyPrice()) { Auth::user()->decrement('credits', $server->product->getHourlyPrice()); } } @@ -86,15 +88,24 @@ class ServerController extends Controller /** * @return null|RedirectResponse */ - private function validateConfigurationRules(){ + private function validateConfigurationRules() + { //limit validation if (Auth::user()->servers()->count() >= Auth::user()->server_limit) { return redirect()->route('servers.index')->with('error', 'Server limit reached!'); } - //minimum credits - if (Auth::user()->credits <= Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50)) { - return redirect()->route('servers.index')->with('error', "You do not have the required amount of ".CREDITS_DISPLAY_NAME." to create a new server!"); + // minimum credits + if (FacadesRequest::has("product_id")) { + $product = Product::findOrFail(FacadesRequest::input("product_id")); + if ( + Auth::user()->credits < + ($product->minimum_credits == -1 + ? Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50) + : $product->minimum_credits) + ) { + return redirect()->route('servers.index')->with('error', "You do not have the required amount of " . CREDITS_DISPLAY_NAME . " to use this product!"); + } } //Required Verification for creating an server @@ -141,7 +152,7 @@ class ServerController extends Controller * @param Server $server * @return RedirectResponse */ - private function serverCreationFailed(Response $response , Server $server) + private function serverCreationFailed(Response $response, Server $server) { $server->delete(); diff --git a/app/Models/Product.php b/app/Models/Product.php index 68dc8f74..f1725da3 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -6,7 +6,6 @@ use Hidehalo\Nanoid\Client; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Spatie\Activitylog\Traits\LogsActivity; class Product extends Model @@ -17,10 +16,11 @@ class Product extends Model protected $guarded = ['id']; - public static function boot() { + public static function boot() + { parent::boot(); - static::creating(function(Product $product) { + static::creating(function (Product $product) { $client = new Client(); $product->{$product->getKeyName()} = $client->generateId($size = 21); @@ -47,6 +47,6 @@ class Product extends Model */ public function servers(): BelongsTo { - return $this->belongsTo(Server::class , 'id' , 'product_id'); + return $this->belongsTo(Server::class, 'id', 'product_id'); } } diff --git a/database/migrations/2021_10_01_200844_add_product_minimum_credits.php b/database/migrations/2021_10_01_200844_add_product_minimum_credits.php new file mode 100644 index 00000000..162b52e8 --- /dev/null +++ b/database/migrations/2021_10_01_200844_add_product_minimum_credits.php @@ -0,0 +1,32 @@ +float('minimum_credits')->default(-1); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('minimum_credits'); + }); + } +} diff --git a/resources/views/admin/products/create.blade.php b/resources/views/admin/products/create.blade.php index 96935a55..8b7ed49f 100644 --- a/resources/views/admin/products/create.blade.php +++ b/resources/views/admin/products/create.blade.php @@ -10,9 +10,10 @@
@@ -29,12 +30,16 @@
-
+ @csrf
- - + +
@@ -42,78 +47,75 @@
- + @error('name') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- - + + @error('price') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
+
- + @error('memory') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('cpu') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('swap') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- - + + @error('description') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
@@ -121,65 +123,74 @@
- + @error('disk') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
+ +
+ + + @error('minimum_credits') +
+ {{ $message }} +
+ @enderror +
+
- + @error('io') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('databases') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('backups') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('allocations') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
@@ -200,6 +211,11 @@ + @endsection diff --git a/resources/views/admin/products/edit.blade.php b/resources/views/admin/products/edit.blade.php index 5b9b1a3f..dd66ae36 100644 --- a/resources/views/admin/products/edit.blade.php +++ b/resources/views/admin/products/edit.blade.php @@ -10,9 +10,10 @@
@@ -29,22 +30,28 @@
- @if($product->servers()->count() > 0) + @if ($product->servers()->count() > 0)
-

Editing the resource options will not automatically update the servers on pterodactyl's side!

-

Automatically updating resource options on pterodactyl side is on my todo list :)

+

Editing the resource options will not automatically update the servers on pterodactyl's + side!

+

Automatically updating resource options on pterodactyl side is on my + todo list :)

@endif
- + @csrf @method('PATCH')
- disabled) checked @endif name="disabled" class="custom-control-input custom-control-input-danger" id="switch1"> - + disabled) checked @endif name="disabled" + class="custom-control-input custom-control-input-danger" id="switch1"> +
@@ -52,78 +59,74 @@
- + @error('name') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- - + + @error('price') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('memory') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('cpu') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('swap') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- - + + @error('description') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
@@ -131,65 +134,72 @@
- + @error('disk') -
- {{$message}} -
+
+ {{ $message }} +
+ @enderror +
+
+ + + @error('minimum_credits') +
+ {{ $message }} +
@enderror
- + @error('io') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('databases') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('backups') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
- + @error('allocations') -
- {{$message}} -
+
+ {{ $message }} +
@enderror
@@ -210,6 +220,11 @@ + @endsection diff --git a/resources/views/admin/products/show.blade.php b/resources/views/admin/products/show.blade.php index 46d13b5d..62e6ed79 100644 --- a/resources/views/admin/products/show.blade.php +++ b/resources/views/admin/products/show.blade.php @@ -10,10 +10,10 @@
@@ -30,11 +30,15 @@
Product
- - + + {{ csrf_field() }} - {{ method_field("DELETE") }} - + {{ method_field('DELETE') }} +
@@ -47,9 +51,9 @@
- - {{$product->id}} - + + {{ $product->id }} +
@@ -60,9 +64,9 @@
- - {{$product->name}} - + + {{ $product->name }} +
@@ -73,9 +77,26 @@
- - {{$product->price}} - + + {{ $product->price }} + +
+ + + +
+
+
+ +
+
+ + @if ($product->minimum_credits == -1) + {{ $minimum_credits }} + @else + {{ $product->minimum_credits }} + @endif +
@@ -87,9 +108,9 @@
- - {{$product->memory}} - + + {{ $product->memory }} +
@@ -100,9 +121,9 @@
- - {{$product->cpu}} - + + {{ $product->cpu }} +
@@ -113,9 +134,9 @@
- - {{$product->swap}} - + + {{ $product->swap }} +
@@ -126,9 +147,9 @@
- - {{$product->disk}} - + + {{ $product->disk }} +
@@ -139,9 +160,9 @@
- - {{$product->io}} - + + {{ $product->io }} +
@@ -152,9 +173,9 @@
- - {{$product->databases}} - + + {{ $product->databases }} +
@@ -165,9 +186,9 @@
- - {{$product->allocations}} - + + {{ $product->allocations }} +
@@ -178,9 +199,9 @@
- - {{$product->created_at ? $product->created_at->diffForHumans() : ''}} - + + {{ $product->created_at ? $product->created_at->diffForHumans() : '' }} +
@@ -192,9 +213,9 @@
- - {{$product->description}} - + + {{ $product->description }} +
@@ -206,9 +227,9 @@
- - {{$product->updated_at ? $product->updated_at->diffForHumans() : ''}} - + + {{ $product->updated_at ? $product->updated_at->diffForHumans() : '' }} +
diff --git a/resources/views/servers/create.blade.php b/resources/views/servers/create.blade.php index 2427a46a..50e3d1a5 100644 --- a/resources/views/servers/create.blade.php +++ b/resources/views/servers/create.blade.php @@ -10,9 +10,10 @@
@@ -32,29 +33,29 @@
Create Server
-
+ @csrf
+ class="form-control @error('name') is-invalid @enderror"> @error('name') -
- Please fill out this field. -
+
+ Please fill out this field. +
@enderror
+ class="form-control @error('description') is-invalid @enderror"> @error('description') -
- Please fill out this field. -
+
+ Please fill out this field. +
@enderror
@@ -63,13 +64,13 @@
- @foreach($nests as $nest) - - @foreach($nest->eggs as $egg) - + class="custom-select @error('egg_id') is-invalid @enderror"> + @foreach ($nests as $nest) + + @foreach ($nest->eggs as $egg) + @endforeach @endforeach @@ -100,32 +101,39 @@
@error('egg_id') -
- Please fill out this field. -
+
+ Please fill out this field. +
@enderror
@error('product_id') -
- Please fill out this field. -
+
+ Please fill out this field. +
@enderror
-