尽管我的直觉告诉我这是一个基本原理,但我一生都无法找到有关如何做到这一点的信息。
我有一个简单的 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/