我是 laravel 的新手,我不想浪费我的时间来寻找雄辩的脚本来运行我的复杂查询脚本,有没有适合我的方法。只需将我拥有的查询脚本(选择、插入、更新、删除)写入 laravel 项目,一切都按我想要的那样工作?这是我选择数据的示例代码,我想用纯查询脚本替换雄辩的function getClaim(){ $data_claim = \App\ClaimModel::all(); return response()->json( [ "message" => $data_claim ] ); }
3 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
做这个
插入查询
$insert = DB::insert("insert into some_table (col1, col2, col3) values ('value1', 'value2', 'value3')");
选择查询
$results = DB::select("select * from some_table where some_col = 'some_value'");
更新查询
$update = DB::update("update some_table set col1 = ? , col2 = ? where col3 = ?", ['value1' , 'value2', 'value3']);
删除查询
$delete = DB::delete('delete from some_table where col = ?',['value']);
您也可以一次删除多行。喜欢
$delete = DB::delete('delete from users where id = ?',[1, 2, 3]);
慕的地6264312
TA贡献1817条经验 获得超6个赞
$users = DB::select('select * from users where active = ?', [1]); return view('user.index', ['users' => $users]);
慕沐林林
TA贡献2016条经验 获得超9个赞
你可以这样做
对于选择查询
$users = DB::select('select * from users where active = ?', [1]);
对于更新查询
$affected = DB::update('update users set votes = 100 where name = ?', ['John']);
对于删除查询
$deleted = DB::delete('delete from users');
对于插入查询
DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);
- 3 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消