我是laravel新手,我有两个问题:
2. 如何在注册时插入自定义值?
我在AuthController中尝试过,但0情绪,没有插入:
默认值:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
我试过但不行:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'seo_name' => str_slug($data['name']),
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
但什么都没发生。为什么?在此先感谢;)
P.S我在PhpMyAdmin中有seo_name
行,我想在注册成功时插入例如:
名称 - 自定义名称
seo_name - 自定义名称(str_slug函数生成该字符串,但IDK如何插入..)
答案 0 :(得分:2)
- 如何设置“来自:”密码提醒发送者?因为现在没有打印
醇>
在Laravel中,您可以使用Mail类来使用SwiftMailer库。这样您就可以访问$message->from('youremail@emailaddress.com', 'Firstname Lastname');
这是一个例子 -
Mail::send('emails.emailview', $data, function($message) {
$message->from('youremail@emailaddress.com', 'Firstname Lastname');
$message->to('to@emailaddress.com')->cc('anotherperson@emailaddress.com');
});
- 如何在注册时插入自定义值?
醇>
您必须使用$fillable
属性中的新字段更新用户模型。这应该反映您为新字段添加的表的名称。
class User extends Eloquent {
protected $guarded = array('id', 'password');
protected $fillable = array('name', 'seo_name', 'email');
}
答案 1 :(得分:0)
要插入自定义值,必须使用上述方法class Mount {
isMounted=false;
getMounted=()=>{
return isMounted;
}
setMounted=mounted=>{
isMounted=mounted;
}
}
var mount=new Mount();
export default mount;
class example extends component{
componentDidMount=async()=>{
mount.setMounted(true);
await this.loadScreen();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
async() => {
await this.loadScreen();
}
);
}
loadScreen=async()=>{
//some other stuff
if(mount.getMounted()){//second time value is false
this.setState({value:'value'});
}
}
componentWillUnmount() {
mount.setMounted(false);
}
//renderview where i call example2 on buttonclick
}
class example2 extends component{
componentDidMount=async()=>{
mount.setMounted(true);
await this.loadScreen();
}
loadScreen=async()=>{
//some other stuff
if(mount.getMounted()){
this.setState({value:'value'});
this.props.navigation.goBack();
}
}
componentWillUnmount() {
mount.setMounted(false);
this.willFocusSubscription.remove();
}
}
。将$fillable
插入模型并添加需要插入的字段。
例如
$fillable
然后添加受保护的$this->db->table('tb_name')->create([name => $value,
address => $val,
...
]);