|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/lecturebazaar.com/app/Http/Controllers/Web/ |
Upload File : |
<?php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\Favorite;
use App\Models\Webinar;
class FavoriteController extends Controller
{
public function toggle($slug)
{
$userId = auth()->id();
$webinar = Webinar::where('slug', $slug)
->where('status', 'active')
->first();
if (!empty($webinar)) {
$isFavorite = Favorite::where('webinar_id', $webinar->id)
->where('user_id', $userId)
->first();
if (empty($isFavorite)) {
Favorite::create([
'user_id' => $userId,
'webinar_id' => $webinar->id,
'created_at' => time()
]);
} else {
$isFavorite->delete();
}
}
return response()->json([], 200);
}
}