pity689 2022-09-15 17:43 采纳率: 50%
浏览 13

Laravel 框架书写接口测试问题报错500

问题遇到的现象和发生背景

数据库CRUD接口测试报错,不知道报错原因,使用的是PHP Laravell框架书写的api接口

img

用代码块功能插入代码,请勿粘贴截图

model层代码
namespace App\model;

use Illuminate\Database\Eloquent\Model;

class crud extends Model
{
protected $table="count";
protected $primaryKey="id";
public $timestamps = true;
protected $guarded = [];

public  static  function Find($id)
{
    try{
        $res =self::select('*')->where('id', $id)->get();
        return $res;
    }catch (\Exception $exception){
        echo $exception->getMessage();
        return false;
    }

}
public  static  function Insert($name,$id)
{
    try{
        $res =self::create([
                'name' =>$name,
                'id' =>$id
            ]
        );
        return $res;
    }catch (\Exception $exception){
        echo $exception->getMessage();
        return false;
    }

}
public  static  function remove($id)
{
    try{
        $res =self::where('id', $id)->delete();
        return $res;
    }catch (\Exception $exception){
        echo $exception->getMessage();
        return false;
    }

}
public  static  function upda($name,$id)
{
    try{
        $res =self::where('id', $id)->update(
            [
                'name'=>$name,
                'id'=>$id
            ]
        );

        return $res;
    }catch (\Exception $exception){
        echo $exception->getMessage();
        return false;
    }

}

}

URL

Route::get("check", "TestController@Check");
Route::get("insert", "TestController@ins");
Route::get("delete", "TestController@dele");
Route::get("update", "TestController@updat");

Controller
namespace App\Http\Controllers;

use App\crud;
use Illuminate\Http\Request;

class TestController extends Controller
{
/**
* 查询数据库
*/
public function Check(Request $request){
$id = $request['id']; //获取表单数据id
$res=crud::Find($id);
return $res?
response()-> json(array('msg'=>'成功','data'=>$res),200):
response()-> json(array('msg'=>'失败','data'=>null),100);

}
public function  ins(Request  $request){
    $name = $request['name'];
    $id =  $request['id'];
    $res=crud::Insert($name,$id);
    return $res?
        response()-> json(array('msg'=>'成功','data'=>$res),200):
        response()-> json(array('msg'=>'失败','data'=>null),100);
}

public function  dele(Request  $request){
    $id =  $request['id'];
    $res=crud::remove($id);
    return $res?
        response()-> json(array('msg'=>'成功','data'=>$res),200):
        response()-> json(array('msg'=>'失败','data'=>null),100);

}
public function  updat(Request  $request){
    $name = $request['name'];
    $id =  $request['id'];
    $res=crud::upda($name,$id);
    return $res?
        response()-> json(array('msg'=>'成功','data'=>$res),200):
        response()-> json(array('msg'=>'失败','data'=>null),100);

}

}

运行结果及报错内容

img


**
apifox中报错内容**

img

  • 写回答

1条回答 默认 最新

  • yt_php 2022-09-16 10:36
    关注

    贴代码没用,报错已经很明白了,直接看报错信息就可以了

    img

    评论

报告相同问题?

问题事件

  • 创建了问题 9月15日

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝