无法更新用户laravel并尝试捕获

时间:2019-02-24 08:03:03

标签: php laravel

我很困惑。我认为我所做的一切都很好,但是我无法更新用户数据,这是我的

web.php

SELECT
    group_id,
    player_id AS winner_id
FROM players AS p
    LEFT JOIN (
        SELECT
            sum(first_score) AS total_first,
            first_player
        FROM matches
        GROUP BY first_player
        ) AS a
        ON p.player_id = a.first_player
    LEFT JOIN (
        SELECT
            sum(second_score) as total_second,
            second_player
        FROM matches
        GROUP BY second_player
        ) AS b
        ON p.player_id = b.second_player
    GROUP BY
        p.group_id,
        p.player_id
    ORDER BY
        coalesce(total_first, 0) + coalesce(total_second, 0) DESC,
        player_id ASC

我不想使用资源,因为我必须自定义自己的路线。

HTML

Route::match(['put', 'patch'], '/is-active','Frontend\UserController@update')->name('user.active');

控制器

 <form action="{{ route('user.active') }}" method="POST" enctype="multipart/form-data">
     {{ csrf_field() }}
    {{ method_field('PUT')}}
    <input type="submit">
</form>

这是我在 DB::beginTransaction(); try { $user = User::find(Auth::id()); $user->active = '3'; //waiting approve $user->save(); dd($user->active,$user->save()); } catch (Exception $e) { die($e->message()); DB::rollback(); } 中的输出

dd()

在我尝试删除try catch之后,一切正常。为什么我不能在此查询中使用try catch?

1 个答案:

答案 0 :(得分:2)

我想,您忘记了DB::commit()try块的末尾使用它