This build disables Backpack authentication and enables standard Laravel authentication methods. Authorization laravel/ui bootstrap is enabled by default. Account confirmation by email is also included. Authorization via social networks has also been added. The user's account can be protected using two-factor authentication.
Also, an example of how Backpack packages work on the frontend has been added to the assembly.
Localization of all routes is present. Make a multilingual website from scratch.
Laravel | Backpack | Auth |
---|---|---|
8.x (PHP version >= 7.3 required) | 5.x | 1.0.x |
9.x (PHP version >= 8.0 required) | 5.x | 2.0.x |
10.x (PHP version >= 8.1 required) | 5.x | 3.0.x |
10.x (PHP version >= 8.1 required) | 6.x | 4.0.x |
11.x (PHP version >= 8.2 required) | 6.x | 5.0.x |
Demonstration: S01
Clone the repository to your server directory:
git clone https://github.com/SequelONE/laravel-auth-backpack.git
Rename the .env.example
file to .env
Be sure to change the localhost
to your domain or IP address without slash in end.
APP_URL=http://localhost
APP_DOMAIN=localhost
Example:
APP_URL=https://sequel.one
APP_DOMAIN=sequel.one
Run the command:
composer update
Generate a key for Laravel:
php artisan key:generate
Then run the command:
npm install && npm run build
Create a symbolic link to the file storage folder:
php artisan storage:link
Configure the file .env
for database access:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
After configuring the database, run the command:
php artisan migrate
Add the default content to the database:
php artisan db:seed
Or run this command to completely delete and re-create tables and data.
php artisan migrate:fresh --seed
Added support for multi-domain through contexts.
After installing the seeders, it is necessary to change the default host to the host of your site in the admin panel in the contexts (http://localhost/admin/context) section.
Pages linked to contexts will be displayed only on the specified subdomain or other domain. In the menu, items with the selected context are displayed only on are displayed only on a specific subdomain or domain.
Password | Access | |
---|---|---|
[email protected] | password | Admin Access |
[email protected] | password | Developer Access |
[email protected] | password | Manager Access |
[email protected] | password | User Access |
[email protected] | password | Banned Access |
Also set up your mail server in file .env
:
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
Setting up a mail server is necessary to receive emails for user confirmation.
Example of setting up a yandex mail server:
MAIL_MAILER=smtp
MAIL_HOST=smtp.yandex.ru
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
To install Backpack, run the following commands:
composer require --dev backpack/generators
and
php artisan backpack:install
php artisan backpack:filemanager:install
php artisan basset:install
#OPTIONAL - publish the config file.
php artisan vendor:publish --provider="Backpack\Basset\BassetServiceProvider"
Basset is disabled by default on local environment. If you want to change it, please set BASSET_DEV_MODE=false in your env file.
In .env
:
BASSET_DEV_MODE=false
For local from CDNs:
// instead of
<link href="{{ asset('path/to/public/file.css') }}">
// you can do
<link href="{{ basset('path/to/public/file.css' }}">
<link href="{{ basset('https://cdn.com/path/to/file.css') }}">
<link href="{{ basset(base_path('vendor/org/package/assets/file.css')) }}">
<link href="{{ basset(storage_path('file.css')) }}">
php artisan basset:cache # internalizes all @bassets
php artisan basset:clear # clears the basset directory
- See full list of providers: https://socialiteproviders.github.io
-
Go to https://socialiteproviders.github.io and select the provider to be added.
-
From the projects root folder, in the terminal, run composer to get the needed package.
- Example:
composer require socialiteproviders/facebook
-
From the projects root folder run
composer update
-
Add the service provider to
/config/services.php
- Example:
'facebook' => [ 'client_id' => env('FACEBOOK_CLIENT_ID'), 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), 'redirect' => env('FACEBOOK_CALLBACK_URL'), ],
-
Add the API credentials to
/.env
- Example:
FACEBOOK_CLIENT_ID=YOURKEYHERE FACEBOOK_CLIENT_SECRET=YOURSECRETHERE FACEBOOK_CALLBACK_URL="${APP_URL}/auth/provider/facebook/callback"
-
Add the social media login link:
- Example:
In file
/resources/views/auth/login.blade.php
add ONE of the following:- Conventional HTML:
<a href="{{ route('social.redirect','facebook') }}" class="btn btn-outline-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Login with Facebook"><i class="fa-brands fa-facebook"></i></a>
- Example:
In file
Example .env
file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost/
APP_LOG=daily
APP_DOMAIN=localhost
BACKPACK_THEME=backpack.theme-tabler
BASSET_DEV_MODE=false
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
DB_PREFIX=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
[email protected]
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
OTP_ENABLED=true
OTP_LIFETIME=1
OTP_KEEP_ALIVE=true
OTP_THROW_EXCEPTION=true
API_DOMAIN=api.site.com
RECAPTCHA_SITE_KEY=YOUR_API_SITE_KEY
RECAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY
FACEBOOK_CLIENT_ID=YOUR_CLIENT_ID
FACEBOOK_CLIENT_SECRET=YOUR_CLIENT_SECRET
FACEBOOK_CALLBACK_URL="${APP_URL}/auth/provider/facebook/callback"
GITHUB_CLIENT_ID=YOUR_CLIENT_ID
GITHUB_CLIENT_SECRET=YOUR_CLIENT_SECRET
GITHUB_CALLBACK_URL="${APP_URL}/auth/provider/github/callback"
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_CLIENT_SECRET
GOOGLE_REDIRECT_URI="${APP_URL}/auth/provider/google/callback"
TWITTER_CLIENT_ID=YOUR_CLIENT_ID
TWITTER_CLIENT_SECRET=YOUR_CLIENT_SECRET
TWITTER_REDIRECT_URI="${APP_URL}/auth/provider/twitter/callback"
VKONTAKTE_CLIENT_ID=YOUR_CLIENT_ID
VKONTAKTE_CLIENT_SECRET=YOUR_CLIENT_SECRET
VKONTAKTE_REDIRECT_URI="${APP_URL}/auth/provider/vkontakte/callback"
YANDEX_CLIENT_ID=YOUR_CLIENT_ID
YANDEX_CLIENT_SECRET=YOUR_CLIENT_SECRET
YANDEX_REDIRECT_URI="${APP_URL}/auth/provider/yandex/callback"
IPDATA_API_KEY=YOUR_API_KEY
MAXMIND_LICENSE_KEY=YOUR_LICENSE_KEY
In some cases, it is necessary to throw off the cache:
php artisan optimize:clear
By default, the following packages have been added and configured: