57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\RecommendationRequest;
|
|
use App\Models\Criteria;
|
|
use App\Services\ToyRecommendationService;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Product;
|
|
|
|
class RecommendationController extends Controller
|
|
{ #untuk mengelola proses rekomendasi mainan, termasuk menampilkan form rekomendasi dan menampilkan hasil rekomendasi berdasarkan input pengguna
|
|
public function __construct(
|
|
protected ToyRecommendationService $sawService
|
|
) {
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$criterias = Criteria::orderBy('weight_order')->get();
|
|
|
|
$categories = Product::select('category')
|
|
->distinct()
|
|
->orderBy('category')
|
|
->pluck('category');
|
|
|
|
return view('user.recommendation', compact(
|
|
'criterias',
|
|
'categories'
|
|
));
|
|
}
|
|
|
|
public function result(RecommendationRequest $request)
|
|
{
|
|
$input = [
|
|
'age_min' => $request->age_min,
|
|
'age_max' => $request->age_max,
|
|
'budget_min' => $request->budget_min,
|
|
'budget_max' => $request->budget_max,
|
|
'priorities' => $request->input('priorities', []),
|
|
'category' => $request->category,
|
|
];
|
|
|
|
$data = $this->sawService->getRecommendationsWithMatrix($input);
|
|
|
|
return view('user.recommendation-result', [
|
|
'recommendations' => $data['recommendations'],
|
|
'input' => $input,
|
|
'criterias' => $data['criterias'],
|
|
'decision_matrix' => $data['decision_matrix'],
|
|
'normalized_matrix' => $data['normalized_matrix'],
|
|
'weights' => $data['weights'],
|
|
'preference_scores' => $data['preference_scores'],
|
|
]);
|
|
}
|
|
}
|