[英]How Can I Login In Laravel With Predefined Email/Username and Password?
I want to login with predefined email address and password in laravel.It will be done in manually. 我想在laravel中使用预定义的电子邮件地址和密码登录,将手动完成。 what will be the process?
流程将如何? I have set login page.
我已经设置了登录页面。 and now i want to login my dashboard without registering and with predefined email and password.
现在我想不注册而使用预定义的电子邮件和密码登录仪表板。
<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>
How can i do that,what will the process thanks for help. 我该怎么办,该过程将对您有所帮助。
Creade a seeder class; 增加播种班级;
php artisan make:seeder UsersTableSeeder
the file will be generated at seeders folder open it and create a default user like so: php artisan make:seeder UsersTableSeeder
文件将在php artisan make:seeder UsersTableSeeder
文件夹中生成,打开该文件并创建一个默认用户,如下所示:
User::create(['name'=>'test',
'email'=>'email',
'password'=>bcrypt('password')]);
at the top. 在顶部。
use User
or do: use User
或执行以下操作:
{
DB::table('users')->insert([
'name' => 'User1',
'email' => 'user1@email.com',
'password' => bcrypt('password'),
]);
after this; 在这之后; add to execute with
$this->call(UsersTableSeeder::class);
添加以执行
$this->call(UsersTableSeeder::class);
in DatabaseSeeder.php
or install in seeds folderfile and call the custom seeder 在
DatabaseSeeder.php
或安装在种子文件夹文件中并调用自定义播种器
then each time you want to have a default user after migration run php artisan db: seed
然后每次您要在迁移后拥有默认用户时运行
php artisan db: seed
I think creating new Artisan Console command is a good choice rather than db:seed
. 我认为创建新的Artisan Console命令比
db:seed
更好。 Through this way, you can define your own username, email, password DYNAMICALLY like you asked, instead of just hardcoding. 通过这种方式,你可以定义自己的用户名,电子邮件,密码, 动态地喜欢你问,而不是仅仅硬编码。 Tested in Laravel 5.4
在Laravel 5.4中测试
1) Create a Artisan Console command using below, which will create a AddLogin.php
inside app/Console/Commands
php artisan make:command AddLogin 2) Replace the AddLogin
content with the following 1)创建使用以下一个工匠控制台命令,该命令将创建一个
AddLogin.php
内部app/Console/Commands
的PHP人员化妆:命令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) Register the command in app/Console/Kernel.php
file by adding 3)通过添加将命令注册到
app/Console/Kernel.php
文件中
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\AddLogin::class
];
4) Whenever you want to create a new Login Credentials, just type 4)每当您要创建新的登录凭据时,只需键入
php artisan add:login
in cmd and provide promted details. 在cmd中,并提供提示的详细信息。
DONE. DONE。 Hope this is useful to someone.
希望这对某人有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.