By GokiSoft.com| 19:03 02/12/2022|
Học Laravel

[Bài Viết] Hướng dẫn cấu hình cơ sở dữ liệu và bật chức năng auth có sẵn trong Laravel BT151

Bước 1 : Truy cập vào

http://localhost/phpmyadmin/

Bước 2 : Vào thư mục của dự án Laravel - htdocs/gokisoft như bài trước. Mở file .env

Tìm đoạn code

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Và sửa thành

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=gokisoft
DB_USERNAME=root
DB_PASSWORD=

Bước 3 : Mở cmd và vào thư mục gốc gokisoft mà thực hiện lệnh sau 

For Laravel < 6

php artisan make:auth

For Laravel >= 6

php artisan migrate
composer require laravel/ui
npm install
php artisan ui vue --auth
npm install && npm run dev

Nếu gặp lỗi trong quá trình cài đặt với Laravel >= 6 thì chạy thêm lệnh sau

npm audit fix

Kiểm tra phiên bản Laravel

php artisan --version

Trường hợp sau khi cài đặt -> bị missing app.css & app.js thì thực hiện lại theo bộ lệnh sau 1 lần nữa

composer require laravel/ui
php artisan ui:auth
php artisan ui bootstrap --auth
npm install && npm run dev

Bước 4 : Sửa lại cấu hình

Mở file : App/Providers/AppServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider {
	/**
	 * Bootstrap any application services.
	 *
	 * @return void
	 */
	public function boot() {
		//
	}

	/**
	 * Register any application services.
	 *
	 * @return void
	 */
	public function register() {
		//
	}
}

Sửa lại thành

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;

class AppServiceProvider extends ServiceProvider {
	/**
	 * Bootstrap any application services.
	 *
	 * @return void
	 */
	public function boot() {
		Schema::defaultStringLength(191);Paginator::useBootstrap();
	}

	/**
	 * Register any application services.
	 *
	 * @return void
	 */
	public function register() {
		//
	}
}

Bước 5 : Thực hiện lệnh

For Laravel < 6

php artisan migrate

Mờ lại link 

http://localhost/gokisoft/public/

Chúng ta có giao diện mới

Liên kết rút gọn:

https://gokisoft.com/151

Bình luận