如何使用预定义的电子邮件/用户名和密码登录Laravel?

时间:2017-08-25 14:06:45

标签: php laravel laravel-5 login

我想在laravel中使用预定义的电子邮件地址和密码登录。它将手动完成。这个过程会是什么?我已经设置了登录页面。现在我想登录我的仪表板而无需注册并使用预定义的电子邮件和密码。

<form class="login-form" action="dashboard.html">        
 <div class="login-wrap">
  <p class="login-img"><i class="icon_lock_alt"></i></p>

 <div class="input-group">
  <span class="input-group-addon"><i class="icon_profile"></i></span>
 <input type="text" class="form-control" placeholder="Username" autofocus>
                    </div>
 <div class="input-group">
  <span class="input-group-addon"><i class="icon_key_alt"></i></span>           
 <input type="password" class="form-control" placeholder="Password">
  </div>
 <button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>

 </div>
  </form>

我该怎么做,这个过程会有什么帮助。

2 个答案:

答案 0 :(得分:1)

创建一个播种者类; php artisan make:seeder UsersTableSeeder该文件将在seeders文件夹中生成并打开它,并创建一个默认用户:

User::create(['name'=>'test',
'email'=>'email',
'password'=>bcrypt('password')]);

在顶部。 use User 或者做:

{
    DB::table('users')->insert([
        'name' => 'User1',
        'email' => 'user1@email.com',
        'password' => bcrypt('password'),
    ]);

之后;添加以执行$this->call(UsersTableSeeder::class);DatabaseSeeder.php中或安装在种子文件夹文件中并调用自定义播种器

然后每次您希望在迁移后运行默认用户php artisan db: seed

答案 1 :(得分:0)

我认为创建新的 Artisan控制台命令是一个不错的选择,而不是db:seed。通过这种方式,您可以像您要​​求的那样定义自己的用户名,电子邮件,密码动态,而不仅仅是硬编码。在Laravel 5.4中测试

1)使用下面创建Artisan控制台命令,这将在AddLogin.php内创建app/Console/Commands     php artisan make:命令AddLogin 2)用以下内容替换AddLogin内容     

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\User;    //User Model

class AddLogin extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'add:login';    //our new artisan console command

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create New Login Credentials';


    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $name = $this->ask('Enter Name :');
        $email = $this->ask('Enter Email :');
        $password = $this->secret('Enter Password :');
        //Password won't be visible when you type

        User::create([
            'name' => $name,
            'email' => $email,
            'password' => bcrypt($password)
        ]);

        $this->info('New Login Credentials created successfully!');
    }
}

3)通过添加

app/Console/Kernel.php文件中注册命令
/**
 * The Artisan commands provided by your application.
 *
 * @var array
 */
protected $commands = [
    Commands\AddLogin::class
];

4)每当您想要创建新的登录凭据时,只需输入

即可
php artisan add:login

在cmd中并提供预定的详细信息。

DONE。希望这对某人有用。

enter image description here

相关问题