Skip to content

Instantly share code, notes, and snippets.

@introqt
Created July 20, 2020 10:41
Show Gist options
  • Save introqt/a5584b275f0fcad56baae2f25740480d to your computer and use it in GitHub Desktop.
Save introqt/a5584b275f0fcad56baae2f25740480d to your computer and use it in GitHub Desktop.
<?php
namespace Modules\Product\Http\Requests\Admin\Product;
use App\Core\Requests\Admin\BaseAdminRequest;
use App\Rules\CheckExistsUrlIfNotFillUrl;
use Illuminate\Validation\Rule;
use Modules\Product\Entities\Product;
use Modules\Product\Entities\ProductVariation;
/**
* Class StoreCountryRequest
*
* @package Modules\Product\Http\Requests\Admin
*/
class UpdateProductRequest extends BaseAdminRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return backpack_auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$product_table_name = (new Product())->getTable();
$variations_table_name = (new ProductVariation())->getTable();
return [
'variations' => [
'array',
],
'variations.*.h1' => [
'required',
'string',
'min:0',
'max:255',
Rule::unique($product_table_name, 'h1')->ignore(\Request::instance()->id, "id"),
Rule::unique($variations_table_name, 'h1')->ignore(\Request::instance()->id, "id")
],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment