Php Mysql:一般错误不正确的整数值

Php Mysql:一般错误不正确的整数值,php,mysql,sql,laravel,Php,Mysql,Sql,Laravel,我知道这个问题已经被问过了,但我找不到一个好的答案 视图看起来像: @foreach ($projects as $key => $project) <tr id="{{$project->id}}"> <td>{{$project->id}}</td> <td>{{$project->slug}}

我知道这个问题已经被问过了,但我找不到一个好的答案

视图看起来像:

@foreach ($projects as $key => $project)
                    <tr id="{{$project->id}}">
                      <td>{{$project->id}}</td>
                      <td>{{$project->slug}}</td>
                      <td>{{$project->order}}</td>
                      <td>{{$project->public}}</td>
                      <td><a href="{{ route('admin.projects.show', $project->id)}}" class="btn btn-info btn-sm">View</a> <a href="{{ route('admin.project.edit', $project->id)}}" class="btn btn-success btn-sm">Edit</a></td>
                    </tr>
@endforeach
$("tbody").sortable({
    items: "> tr",
    appendTo: "parent",
    helper: "clone",
    update: function( event, ui ) {
        let newOrder = $(this).sortable('toArray');
        $.ajax({
            type: "POST",
            url:'/admin/projects/updateOrder',
            data: {ids: newOrder}
        })
       .done(function( msg ) {
            // render table with new order?
       });
    }
}).disableSelection();
public function updateOrder(Request $request)
    {
        $ids = $request->ids;
        // en el array ids, los "keys" serían el orden, los cuales puedes modificar según lo que requieras

        $caseQuery = 'CASE id ';
        foreach ($ids as $order => $id) {
            $caseQuery .= "WHEN $id THEN $order ";
        }
        $caseQuery .= ' END CASE';
            DB::table('projects')
                ->whereIn('id', $ids)
                ->update(['order' => $caseQuery]);
    }    
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'CASE 
id WHEN 2 THEN 0 WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 WHEN 5 
THEN 4 WHEN 6 THEN 5 WHEN 7 THEN 6 WHEN 8 THEN 7 WHEN 9 T' for column 
'order' at row 1 (SQL: update `projects` set `order` = CASE id WHEN 2 
THEN 0 WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 WHEN 5 THEN 4 WHEN 6 
THEN 5 WHEN 7 THEN 6 WHEN 8 THEN 7 WHEN 9 THEN 8 WHEN 10 THEN 9 WHEN 
11 THEN 10 WHEN 12 THEN 11 WHEN 13 THEN 12 WHEN 14 THEN 13 WHEN 15 
THEN 14 WHEN 16 THEN 15 WHEN 17 THEN 16 WHEN 18 THEN 17 WHEN 19 THEN 
18 WHEN 20 THEN 19 WHEN 21 THEN 20 WHEN 22 THEN 21 WHEN 23 THEN 22 
WHEN 24 THEN 23 WHEN 25 THEN 24 WHEN 26 THEN 25 WHEN 27 THEN 26 WHEN 
28 THEN 27 WHEN 29 THEN 28 END CASE where `id` in (2, 3, 1, 4, 5, 6, 
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 28, 29))
控制器功能如下所示:

@foreach ($projects as $key => $project)
                    <tr id="{{$project->id}}">
                      <td>{{$project->id}}</td>
                      <td>{{$project->slug}}</td>
                      <td>{{$project->order}}</td>
                      <td>{{$project->public}}</td>
                      <td><a href="{{ route('admin.projects.show', $project->id)}}" class="btn btn-info btn-sm">View</a> <a href="{{ route('admin.project.edit', $project->id)}}" class="btn btn-success btn-sm">Edit</a></td>
                    </tr>
@endforeach
$("tbody").sortable({
    items: "> tr",
    appendTo: "parent",
    helper: "clone",
    update: function( event, ui ) {
        let newOrder = $(this).sortable('toArray');
        $.ajax({
            type: "POST",
            url:'/admin/projects/updateOrder',
            data: {ids: newOrder}
        })
       .done(function( msg ) {
            // render table with new order?
       });
    }
}).disableSelection();
public function updateOrder(Request $request)
    {
        $ids = $request->ids;
        // en el array ids, los "keys" serían el orden, los cuales puedes modificar según lo que requieras

        $caseQuery = 'CASE id ';
        foreach ($ids as $order => $id) {
            $caseQuery .= "WHEN $id THEN $order ";
        }
        $caseQuery .= ' END CASE';
            DB::table('projects')
                ->whereIn('id', $ids)
                ->update(['order' => $caseQuery]);
    }    
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'CASE 
id WHEN 2 THEN 0 WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 WHEN 5 
THEN 4 WHEN 6 THEN 5 WHEN 7 THEN 6 WHEN 8 THEN 7 WHEN 9 T' for column 
'order' at row 1 (SQL: update `projects` set `order` = CASE id WHEN 2 
THEN 0 WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 WHEN 5 THEN 4 WHEN 6 
THEN 5 WHEN 7 THEN 6 WHEN 8 THEN 7 WHEN 9 THEN 8 WHEN 10 THEN 9 WHEN 
11 THEN 10 WHEN 12 THEN 11 WHEN 13 THEN 12 WHEN 14 THEN 13 WHEN 15 
THEN 14 WHEN 16 THEN 15 WHEN 17 THEN 16 WHEN 18 THEN 17 WHEN 19 THEN 
18 WHEN 20 THEN 19 WHEN 21 THEN 20 WHEN 22 THEN 21 WHEN 23 THEN 22 
WHEN 24 THEN 23 WHEN 25 THEN 24 WHEN 26 THEN 25 WHEN 27 THEN 26 WHEN 
28 THEN 27 WHEN 29 THEN 28 END CASE where `id` in (2, 3, 1, 4, 5, 6, 
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 28, 29))
错误:

@foreach ($projects as $key => $project)
                    <tr id="{{$project->id}}">
                      <td>{{$project->id}}</td>
                      <td>{{$project->slug}}</td>
                      <td>{{$project->order}}</td>
                      <td>{{$project->public}}</td>
                      <td><a href="{{ route('admin.projects.show', $project->id)}}" class="btn btn-info btn-sm">View</a> <a href="{{ route('admin.project.edit', $project->id)}}" class="btn btn-success btn-sm">Edit</a></td>
                    </tr>
@endforeach
$("tbody").sortable({
    items: "> tr",
    appendTo: "parent",
    helper: "clone",
    update: function( event, ui ) {
        let newOrder = $(this).sortable('toArray');
        $.ajax({
            type: "POST",
            url:'/admin/projects/updateOrder',
            data: {ids: newOrder}
        })
       .done(function( msg ) {
            // render table with new order?
       });
    }
}).disableSelection();
public function updateOrder(Request $request)
    {
        $ids = $request->ids;
        // en el array ids, los "keys" serían el orden, los cuales puedes modificar según lo que requieras

        $caseQuery = 'CASE id ';
        foreach ($ids as $order => $id) {
            $caseQuery .= "WHEN $id THEN $order ";
        }
        $caseQuery .= ' END CASE';
            DB::table('projects')
                ->whereIn('id', $ids)
                ->update(['order' => $caseQuery]);
    }    
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'CASE 
id WHEN 2 THEN 0 WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 WHEN 5 
THEN 4 WHEN 6 THEN 5 WHEN 7 THEN 6 WHEN 8 THEN 7 WHEN 9 T' for column 
'order' at row 1 (SQL: update `projects` set `order` = CASE id WHEN 2 
THEN 0 WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 WHEN 5 THEN 4 WHEN 6 
THEN 5 WHEN 7 THEN 6 WHEN 8 THEN 7 WHEN 9 THEN 8 WHEN 10 THEN 9 WHEN 
11 THEN 10 WHEN 12 THEN 11 WHEN 13 THEN 12 WHEN 14 THEN 13 WHEN 15 
THEN 14 WHEN 16 THEN 15 WHEN 17 THEN 16 WHEN 18 THEN 17 WHEN 19 THEN 
18 WHEN 20 THEN 19 WHEN 21 THEN 20 WHEN 22 THEN 21 WHEN 23 THEN 22 
WHEN 24 THEN 23 WHEN 25 THEN 24 WHEN 26 THEN 25 WHEN 27 THEN 26 WHEN 
28 THEN 27 WHEN 29 THEN 28 END CASE where `id` in (2, 3, 1, 4, 5, 6, 
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 28, 29))
有人知道我为什么会犯这个错误吗

这段代码是在我拖放时更新值的

谢谢

更新

控制器功能现在如下所示:

public function updateOrder(Request $request)
    {
        $ids = $request->ids;
        // en el array ids, los "keys" serían el orden, los cuales puedes modificar según lo que requieras

        $caseQuery = 'CASE';
        foreach ($ids as $order => $id) {
            $caseQuery .= "WHEN id = $id THEN $order ";
        }
        $caseQuery .= 'ELSE null';
        $caseQuery .= ' END';
            DB::table('projects')
                ->whereIn('id', $ids)
                ->update(['order' => $caseQuery]);

    }
我在laravel.log上发现的错误如下:

下一步\Database\QueryException:SQLSTATE[HY000]:常规 错误:1366整数值不正确:“当id=26时为CASEWHEN,当id为 =23,当id=19时为1,当id=25时为2,当id=27时为3,当id=18时为4,当第1行的列“顺序”为“时为5”(SQL:update
项目
设置
顺序
=case当id=26时,则为0当id=23时,则为1 当id=19时,当id=25时为2,当id=27时为3,当id=25时为4= 18当id=28时为5,当id=14时为6,当id=24时为7,然后为8 当id=20时,当id=12时为9,当id=13时为10,当id=12时为11 =17,id=29时为12,id=15时为13,id=21时为14,id=16时为15,id=22时为16,id=4时为17,然后为18 当id=3时,当id=1时为19;当id=6时为20;当id=1时为21= 9当id=8时为22当id=5时为23当id=2时为24然后为25 当id=10时为26当id=11时为27当id=7时为28其他 (26,23,19,25,27,18,28,14,24,20,12, 13、17、29、15、21、16、22、4、3、1、6、9、8、5、2、10、11、7 /home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illumb/Database/Connection.php:647 堆栈跟踪: #0/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Database/Connection.php(607): 照亮\Database\Connection->runQueryCallback('update
project…',
数组,对象(闭包))
#1/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Database/Connection.php(477):
照亮\Database\Connection->run('update
project…',数组, 对象(关闭)) #2/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Database/Connection.php(416): 照亮\数据库\连接->影响语句('更新
项目…,数组)
#3/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Database/Query/Builder.php(2152):
照亮\Database\Connection->update('update
project…',数组) #4/home/vagrant/Code/Manifiesto/app/Http/Controllers/AdminController.php(141): 照亮\Database\Query\Builder->update(数组) #5[内部函数]:App\Http\Controllers\AdminController->updateOrder(对象(照亮\Http\Request)) #6/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Controller.php(55): 调用用户函数数组(数组,数组) #7/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/ControllerDispatcher.php(44): 照亮\Routing\Controller->callAction('updateOrder',数组) #8/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Route.php(203): 照明\路由\控制器Dispatcher->dispatch(对象(照明\路由\路由), 对象(App\Http\Controllers\AdminController),'updateOrder') #9/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Route.php(160): 照亮\路由\路由->运行控制器() #10/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Router.php(574): 照亮\Routing\Route->run() #11/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Pipeline.php(30): Illumb\Routing\Router->Illumb\Routing{Close}(对象(Illumb\Http\Request)) #12/home/vagrant/Code/Manifiesto/vendor/vsch/laravel translation manager/src/RouteAfterMiddleware.php(21): Illumb\Routing\Pipeline->Illumb\Routing{Close}(对象(Illumb\Http\Request)) #13/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Pipeline/Pipeline.php(148): Vsch\TranslationManager\RouteAfterMiddleware->handle(对象(照亮\Http\Request), 对象(关闭)) #14/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Pipeline.php(53): 照亮\Pipeline\Pipeline->照亮\Pipeline{closure}(对象(照亮\Http\Request)) #15/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Middleware/SubstituteBindings.php(41): Illumb\Routing\Pipeline->Illumb\Routing{Close}(对象(Illumb\Http\Request)) #16/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Pipeline/Pipeline.php(148): 照亮\Routing\Middleware\SubstituteBindings->handle(对象(照亮\Http\Request), 对象(关闭)) #17/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Pipeline.php(53): 照亮\Pipeline\Pipeline->照亮\Pipeline{closure}(对象(照亮\Http\Request)) #18/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/light/Auth/Middleware/Authenticate.php(43): Illumb\Routing\Pipeline->Illumb\Routing{Close}(对象(Illumb\Http\Request)) #19/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Pipeline/Pipeline.php(148): 照亮\Auth\Middleware\Authenticate->handle(对象(照亮\Http\Request), 对象(闭包),“admin”) #20/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Routing/Pipeline.php(53): 照亮\Pipeline\Pipeline->照亮\Pipeline{closure}(对象(照亮\Http\Request)) #21/home/vagrant/Code/Manifiesto/vendor/laravel/framework/src/illusted/Foundation/Http/Middleware/VerifyCsrfToken.php(65): Illumb\Routing\Pipeline->Illumb\Routing{Close}(对象(Illumb\Http\Request)) #22/家庭/流浪者/代码/马尼菲斯托/供应商/拉维/框架