我在Laravel中通过参数更改值时的请求问题

我有一个函数,要求从表中的每个参数中获取一个值,当发出请求时,表中有一些不读取它们的值,而其他则是,所有值都在表中。所以它不应该为null。

功能:

  public function showMarketByGroup($idGroup)
    {
        $response = array('code' => 400, 'error_msg' => []);
        try {
            $karateka = Karateka::find($idGroup);
            if (!empty($karateka)) {

                $karatekasInMarket = $karateka->karatekasByGroupInMarket;
                return   $response = array('code' => 200, 'karatekas' => $karatekasInMarket, 'msg' => 'Get all karatekas by group in market');
            } else {
                return $response = array('code' => 401, 'error_msg' => 'Unautorized');
            }
        } catch (\Exception $exception) {
            $response = array('code' => 500, 'error_msg' => $exception->getMessage());
        }
        return response($response, $response['code']);
    }

This is the table where I am referencing:

When the column of the id_group has a value of 3 or 4, the answer is correct.
But with the other values ​​it enters an exception in Postman:

{
    "code": 401,
    "error_msg": "Unautorized"
}
评论