Merge branch 'develop' into trunk
This commit is contained in:
commit
247cf327b4
2 changed files with 5 additions and 3 deletions
|
|
@ -23,9 +23,11 @@ class StoreRatingRequest extends FormRequest
|
|||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$table = $this->rating_type === 'App\Models\Product' ? 'products' : 'recipes';
|
||||
|
||||
return [
|
||||
'rate' => 'required|integer|min:0|max:5',
|
||||
'rating_id' => 'required|integer|exists:products,id',
|
||||
'rating_id' => "required|integer|exists:{$table},id",
|
||||
'rating_type' => 'required|in:App\\Models\\Product,App\\Models\\Recipe',
|
||||
'customer_id' => 'required|integer|exists:customers,id',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
|||
|
||||
use App\Enums\RatingEnum;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
|
@ -82,7 +83,7 @@ class Rating extends Model
|
|||
return $model->rate->value();
|
||||
}), 1),
|
||||
'ratings' => $model->ratings()->inRandomOrder()
|
||||
->take(6)->with('customer')->get()->each(function (Rating $rating) {
|
||||
->where('rate', '>', 2)->take(6)->with('customer')->get()->each(function (Rating $rating) {
|
||||
$rating->customer_username = $rating->customer->username;
|
||||
return $rating;
|
||||
}),
|
||||
|
|
@ -94,7 +95,6 @@ class Rating extends Model
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a SchemaOrg.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue