Files
ewaste-backend/app/Http/Requests/UpdateListingRequest.php
2025-11-05 14:47:19 -08:00

36 lines
1007 B
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use App\Models\Listing;
class UpdateListingRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
$listing = Listing::find($this->route('listing'));
return $listing && $this->user()->can('update', $listing);
}
/**
* 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',
];
}
}