HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/mobilech/.trash/repair/app/Http/Controllers/Web/ShopFollowerController.php
<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Model\ShopFollower;
use Carbon\Carbon;

class ShopFollowerController extends Controller
{
    public function __construct(
        private ShopFollower $shop_follower,
    ) {

    }

    public function shop_follow(Request $request)
    {
        if (auth('customer')->check()) {
            $shopFollower = $this->shop_follower->where(['user_id'=>auth('customer')->id(),'shop_id'=>$request->shop_id])->first();
            if ($shopFollower) {
                $shopFollower->delete();
                $followers = $this->shop_follower->where(['shop_id'=>$request->shop_id])->count();

                return response()->json([
                    'text' => translate("follow"),
                    'message' => translate("unfollow_successfully")."!",
                    'value' => 2,
                    'followers' => $followers,
                ]);

            } else {
                $this->shop_follower->insert([
                    'user_id'=>auth('customer')->id(),
                    'shop_id'=>$request->shop_id,
                    'created_at'=>Carbon::now(),
                ]);
                $followers = $this->shop_follower->where(['shop_id'=>$request->shop_id])->count();

                return response()->json([
                    'text' => translate("Unfollow"),
                    'message' => translate("follow_successfully")."!",
                    'value' => 1,
                    'followers' => $followers,
                ]);
            }
        }else{
            return response()->json([
                'message' => translate("Login_first"),
                'value' => 0,
            ]);
        }

    }
}