使用Laravel 5.3将值输入数据库

时间:2017-01-09 17:38:10

标签: php mysql laravel

我不能为我的生活找到关于如何做到这一点的信息,尽管我的直觉告诉我它的基本原理。

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

这是代码:(你可以忽略我所记录的代码。这是针对不同的实现)

Oracle Documentation

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');
    }

}

如果这是常识,我再次道歉,我无法在任何地方找到参考源。要么我能读到这个或方向的链接都会很棒!

1 个答案:

答案 0 :(得分:0)

如果您想输入'客户'在一张叫做“用户”的桌子上在专栏' temproles'你应该能够做到这一点:

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

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

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