feat: complete wishlist in user dashboard
This commit is contained in:
@@ -1,11 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Account;
|
||||
class WishlistController
|
||||
{
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Wishlist;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WishlistController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$wishlists = Wishlist::with(['tour', 'flight'])
|
||||
->where('user_id', auth()->id())
|
||||
->latest()
|
||||
->paginate();
|
||||
|
||||
return view('account.wishlist', compact('wishlists'));
|
||||
}
|
||||
|
||||
public function toggle($type, $id)
|
||||
{
|
||||
$wishlist = Wishlist::where('user_id', auth()->id())
|
||||
->where($type . '_id', $id)
|
||||
->first();
|
||||
|
||||
if ($wishlist) {
|
||||
$wishlist->delete();
|
||||
} else {
|
||||
Wishlist::create([
|
||||
'user_id' => auth()->id(),
|
||||
$type . '_id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Wishlist
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $flight_id
|
||||
* @property int|null $tour_id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property User $user
|
||||
* @property Flight|null $flight
|
||||
* @property Tour|null $tour
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Wishlist extends Model
|
||||
{
|
||||
protected $table = 'wishlists';
|
||||
public static $snakeAttributes = false;
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'flight_id' => 'int',
|
||||
'tour_id' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'flight_id',
|
||||
'tour_id'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function flight()
|
||||
{
|
||||
return $this->belongsTo(Flight::class);
|
||||
}
|
||||
|
||||
public function tour()
|
||||
{
|
||||
return $this->belongsTo(Tour::class, 'tour_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user