6302570d75
git commit "Implement authentication flow and initialize home page hero section"
51 lines
1.0 KiB
PHP
51 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Favorite;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FavoriteController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$favorites=Favorite::with('tour')
|
|
->where('user_id',auth()->id())
|
|
->latest()
|
|
->get();
|
|
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,
|
|
]);
|
|
|
|
return back()->with(
|
|
'success',
|
|
'تور به علاقهمندیها اضافه شد.'
|
|
);
|
|
}
|
|
|
|
|
|
public function destroy(Favorite $favorite)
|
|
{
|
|
|
|
$favorite->delete();
|
|
|
|
return back()->with(
|
|
'success',
|
|
'تور از علاقهمندیها حذف شد.'
|
|
);
|
|
|
|
}
|
|
}
|