git commit "add favorites display with polymorphic relation"
This commit is contained in:
@@ -9,30 +9,24 @@ class FavoriteController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$favorites=Favorite::with('tour')
|
||||
->where('user_id',auth()->id())
|
||||
$favorites = Favorite::with('favoritable')
|
||||
->where('user_id', auth()->id())
|
||||
->latest()
|
||||
->get();
|
||||
return view('account.users.favorite.index',compact('favorites'));
|
||||
|
||||
return view('account.users.favorite.index', compact('favorites'));
|
||||
|
||||
}
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'tour_id'=>[
|
||||
'required',
|
||||
'exists:tours,id'
|
||||
],
|
||||
]);
|
||||
Favorite::firstOrCreate([
|
||||
'user_id' => auth()->id(),
|
||||
'tour_id' => $request->tour_id,
|
||||
'favoritable_type' => $request->type,
|
||||
'favoritable_id' => $request->id,
|
||||
]);
|
||||
|
||||
return back()->with(
|
||||
'success',
|
||||
'تور به علاقهمندیها اضافه شد.'
|
||||
);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user