Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

JuanDMeGon/Laravel-from-Scratch

17 stars
1 code files
View JuanDMeGon/Laravel-from-Scratch on GitHub

app/Http/Requests/ProductRequest.php

Open in GitHub
use Illuminate\Foundation\Http\FormRequest;
 
class ProductRequest extends FormRequest
{
public function authorize()
{
return true;
}
 
public function rules()
{
return [
'title' => ['required', 'max:255'],
'description' => ['required', 'max:1000'],
'price' => ['required', 'min:1'],
'stock' => ['required', 'min:0'],
'status' => ['required', 'in:available,unavailable'],
'images.*' => ['nullable', 'image'],
];
}
 
public function withValidator($validator)
{
$validator->after(function ($validator) {
if ($this->stock == 0 && $this->status == 'available') {
$validator->errors()->add('stock', 'If available must have stock');
}
});
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.