php - 使用 Laravel 5.3 将值输入数据库

标签 php mysql laravel

尽管我的直觉告诉我这是一个基本原理,但我一生都无法找到有关如何做到这一点的信息。

我有一个简单的 bool 值,可以根据表值reference_id 重定向用户。我希望它在用户行的列中输入值后重定向用户。

这是代码:(您可以忽略我注释掉的代码。这是不同的实现)

https://gyazo.com/9f2774cd9069b4678d67b80391f9f276

protected function redirectTo()
{
    $id = Auth::id();
    $rfid = DB::table('users')->where('id', $id)->value('reference_id');
    //$userid = User::find($id);
    if ($rfid == ''){
        //$clientRole = DB::table('roles')->where('id', '2')->value('slug');
        //$userid->attachRole($clientRole); // sets role based on redirect
        input 'client' to database 'users' column 'temproles' //dummy code for what I want to do

        view('/clientdirect');
    }
    else {
        //$employeeRole = DB::table('roles')->where('id', '3')->value('slug');
        //$userid->attachRole($employeeRole); // sets role based on redirect
        input 'employee' to database 'users' column 'temproles'
        view('/empdirect');
    }

}

再次抱歉,如果这是常识,我在任何地方都找不到引用来源。如果有一个指向我可以阅读此内容的链接或说明,那就太好了!

最佳答案

如果您想在“temproles”列中名为“users”的表上输入“client”,您应该能够通过以下方式完成此操作:

DB::table('users')->insert(
    ['temprole' => 'client']
);

如果您已创建模型,则可以执行以下操作:

$user = new User
$user->temproles = 'client';
$user->save();

关于php - 使用 Laravel 5.3 将值输入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41553730/

相关文章:

mysql - 如何在 1 个查询中选择与同一列中的多个元素匹配的不同行?

php - 使用 php 创建自定义的谷歌地图

Laravel Elixir : How to execute a task only in production mode?

php - Wufoo - 发布到表单 API - 表单无法接受新条目

php - 我可以在 PHP 中混合使用 MySQL API 吗?

php - 如何使用中间件将授权 access_token 发送到 Laravel 中的请求 header

php - PHP、MySQL 登录错误

php - 目标 [League\OAuth2\Server\Repositories\ClientRepositoryInterface] 在构建 [League\OAuth2\Server\AuthorizationServer] 时不可实例化

laravel - Lumen/Laravel 从 Http header 获取参数值

php - Fontawesome 里面的提交按钮