feat:complement wishlist for dashboard side
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Account;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Favorite;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class FavoriteController extends Controller
|
||||
{
|
||||
public function toggle($type, $id)
|
||||
{
|
||||
$query = Favorite::where('user_id', Auth::id());
|
||||
|
||||
if ($type === 'flight') {
|
||||
$query->where('flight_id', $id);
|
||||
} elseif ($type === 'tour') {
|
||||
$query->where('tour_id', $id);
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$favorite = $query->first();
|
||||
|
||||
if ($favorite) {
|
||||
$favorite->delete();
|
||||
} else {
|
||||
|
||||
$data = [
|
||||
'user_id' => Auth::id(),
|
||||
];
|
||||
|
||||
if ($type === 'flight') {
|
||||
$data['flight_id'] = $id;
|
||||
} else {
|
||||
$data['tour_id'] = $id;
|
||||
}
|
||||
|
||||
Favorite::create($data);
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user