47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\EanCode;
|
|
use App\Models\Participation;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class WinnerRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
/** @var \App\Models\User */
|
|
$user = auth()->user();
|
|
return auth()->check() and $user->hasWon()->exists();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
/** @var \App\Models\User */
|
|
$user = auth()->user();
|
|
$ids = $user->unclaimedInstantGagnants()->pluck('id')->implode(',');
|
|
return [
|
|
'unclaimedWin' => 'required|integer|exists:instant_gagnants,id|in:' . $ids,
|
|
'firstname' => 'required|string|min:2|max:255',
|
|
'lastname' => 'required|string|min:2|max:255',
|
|
'address' => 'required|min: 5|string|max:255',
|
|
'address2' => 'sometimes|max:255',
|
|
'phone' => 'required|string|min:10|max:13',
|
|
'city' => 'required|string|min: 2|max:255',
|
|
'country' => 'required|string|min: 2|max:255',
|
|
'postcode' => 'required|digits:5',
|
|
'file' => 'required|file|mimes:png,jpg,pdf|max:2048',
|
|
];
|
|
}
|
|
}
|