1、首先安装Sentinel:
composer require cartalyst/sentinel "2.0.*"
2、修改config/app.php
$providers加:Cartalyst\Sentinel\Laravel\SentinelServiceProvider::class,
$aliases加
'Activation' => Cartalyst\Sentinel\Laravel\Facades\Activation::class,
'Reminder' => Cartalyst\Sentinel\Laravel\Facades\Reminder::class,
'Sentinel' => Cartalyst\Sentinel\Laravel\Facades\Sentinel::class,
3、运行php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider"生成配置文件,修改这个配置文件config/cartalyst.sentinel.php :
'model' => 'App\Models\User',
],
4、修改database/migrations/migration_cartalyst_sentinel.php,修改成自己需要的,如:
5、数据迁移,会将标准的数据表迁移到自己的数据库中:
php artisan migrate
6、现在要插入数据的话,需要做些准备:
创建Models/User.php,这样的话默认操作的就是users(首字母变小写加复数)
<?php
namespace App\Models;
use Cartalyst\Sentinel\Users\EloquentUser as SentinelEloquentUser;
class User extends SentinelEloquentUser{
protected $loginNames=['tel']; //设置登录的名字
protected $fillable = [ //设置允许批量修改的属性
'tel',
'name',
'email',
'password'
];
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
class MyController extends Controller{
public function register(Request $request){
$credentials=[
'tel' => '13075534552',
'name' => 'zz',
'password' => '123'
];
$user=Sentinel::registerAndActivate($credentials,true); //注册并激活用户
}
没有$loginNames的话会出现如下问题:
没有$fillabel的话会发现插入在数据库中的值是空的
7、以上做完以后,会在数据库中看到更新的值,但是发现资料更新的时间不是中国,在app.php中:
'timezone' => 'PRC',
这样更新的时候就变成中国了,PRC是中华人民共和国的缩写。
成功的插入数据!密码是自动加密的。