简体   繁体   English

“生成器无法转换为字符串”删除查询时出错 Laravel 5.8

[英]"Builder could not be converted to string" Error on Delete query Laravel 5.8

When the delete sql query rubs it gets the error "Builder could not be converted to string".当删除 sql 查询失败时,它会收到错误“Builder 无法转换为字符串”。 How can I solve this?我该如何解决这个问题?

my code:我的代码:

 public function deleteService(Request $request) { $id = $request->get('delete'); $service = $request->get('service'); $service_id = DB::table('services_info')->select('id')->where('service', '=', $service); DB::delete("DELETE FROM job_service WHERE job_id = {$id} AND service_id = {$service_id}"); }

// you are returning a Builder, no a result
$service_id = DB::table('services_info')->select('id')->where('service', '=', $service);
// add ->value('id')
$service_id = DB::table('services_info')->select('id')->where('service', '=', $service)->value('id');

->value(<column name>) return the first value of <column name> in the query. ->value(<column name>)返回查询中<column name>的第一个值。

In alternative you can fetch the first result of query and then get the value of id: ->first()->id或者,您可以获取查询的第一个结果,然后获取 id 的值: ->first()->id

References: https://laravel.com/docs/7.x/queries参考资料: https://laravel.com/docs/7.x/queries

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Object 的 class Illuminate\Database\Query\Builder 无法转换为 Laravel 中的字符串 - Object of class Illuminate\Database\Query\Builder could not be converted to string in Laravel Laravel 4 Fluent Query Builder-类stdClass的对象无法转换为字符串 - Laravel 4 Fluent Query Builder - Object of class stdClass could not be converted to string Laravel 8 查询 - class 的 Object Illuminate\Database\Eloquent\Builder 无法转换为字符串 - Laravel 8 Query - Object of class Illuminate\Database\Eloquent\Builder could not be converted to string 我收到此错误:无法在Laravel ORM中将Illuminate \\ Database \\ Eloquent \\ Builder类的对象转换为字符串 - i get this error: Object of class Illuminate\Database\Eloquent\Builder could not be converted to string in laravel ORM Object 的 class Illuminate\Database\Eloquent\Builder 无法转换为字符串 laravel 7 - Object of class Illuminate\Database\Eloquent\Builder could not be converted to string laravel 7 Laravel:类 Illuminate\\Database\\Eloquent\\Builder 的对象无法转换为字符串 - Laravel: Object of class Illuminate\Database\Eloquent\Builder could not be converted to string Object 的 class Illuminate\Database\Eloquent\Builder 无法转换为 laravel 中的字符串 8 - Object of class Illuminate\Database\Eloquent\Builder could not be converted to string in laravel 8 错误:类 Illuminate\\Database\\Eloquent\\Builder 的对象无法转换为字符串 - Error: Object of class Illuminate\Database\Eloquent\Builder could not be converted to string Laravel 删除查询生成器 - Laravel Delete Query Builder Laravel eloquent:类Closure 的对象无法转换为字符串连接查询 - Laravel eloquent: Object of class Closure could not be converted to string join query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM