35 lines
941 B
PHP
35 lines
941 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use App\Models\Listing;
|
|
|
|
class StoreListingRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can('create', Listing::class);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'title' => 'string|required|max:100',
|
|
'description' => 'string|required|max:1000',
|
|
'condition' => ['nullable', Rule::in(['parts only', 'poor', 'fair', 'good', 'excellent'])],
|
|
'price' => 'decimal:2|gte:0',
|
|
'location' => 'string|nullable|max:50',
|
|
];
|
|
}
|
|
}
|