<?php

namespace Modules\Advertisement\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Modules\Blog\Entities\Like;

class LikeController extends Controller
{
    function getLike(){
        $like =  Auth::user()->Likes()->get();
        return response()->json([
            'data'  => $like,
            'message'=>'ok',
            'status' => 200
        ]);
    }
    function like(Request $request){
        $like =  Like::firstOrCreate([
            'user_id'=>Auth::user()->id,
            'likable_id'=>$request->likable_id,
            'likable_type'=>$request->likable_type,
        ]);
        if($like->wasRecentlyCreated){
        }else{
            $like->delete();
        }
        return response()->json([
            'data'  => true,
            'message'=>'ok',
            'status' => 200
        ]);
    }
}
