填充方法在寄存器控制器中不起作用
fill method not working in register controller
在使用 model::create 外观创建我的模型后,我使用填充方法更改“card_tb_name”的值 属性 但新值不记录我应该说“card_tb_name" 声明为可填写 属性 .
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
/*------------------------------*/
class RegisteredUserController extends Controller
{
public function store(Request $request)
{
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
'card_tb_name' => 'table_name',
]);
$user->fill(array('card_tb_name' => 'Amsterdam to Frankfurt'));
}
}
在 fill()
之后尝试 save()
$user->fill(array('card_tb_name' => 'Amsterdam to Frankfurt'))->save();
在使用 model::create 外观创建我的模型后,我使用填充方法更改“card_tb_name”的值 属性 但新值不记录我应该说“card_tb_name" 声明为可填写 属性 .
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
/*------------------------------*/
class RegisteredUserController extends Controller
{
public function store(Request $request)
{
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
'card_tb_name' => 'table_name',
]);
$user->fill(array('card_tb_name' => 'Amsterdam to Frankfurt'));
}
}
在 fill()
save()
$user->fill(array('card_tb_name' => 'Amsterdam to Frankfurt'))->save();