Backpack helps you build admin panels faster by:
For the simplest projects, you will never need to know how it works, never need to customize anything but the
config/backpack/base.php file. But here's how everything works, below.
Backpack pulls in our custom HTML template, Backstrap, and adds our own CSS file on top, for a few cosmetic improvements. We've chosen to base Backstrap on CoreUI, because it provides design blocks for all common features of an administration panel. When you decide to build custom pages for your Admin Panel, you can just use Backstrap's HTML blocks - no designer needed. You can see all the HTML components Backstrap provides on backstrap.net, and copy-paste HTML from there, or use CoreUI's documentation for details.
After installation, you'll notice Backpack has added a few files:
1) View to
This file is used to show the contents of the menu to the left (sidebar). It's been published there so that you can easily modify its contents, by editing its HTML.
2) Middleware to
This middleware is used to test if users have access to admin panel pages. You can (and should customize it) if you have both users and admins in your app.
3) Route file to
This route file is for convenience and convention. We recommend you place all your admin panel routes here.
After installation, you'll notice Backpack has added a new blade file in
That file is used to show the contents of the menu to the left (sidebar). It's been published there so that you can easily modify its contents, by editing its HTML or adding dynamic content through widgets.
You can change any blade file to your own needs. Determine what file you'd need to modify if you were to edit directly in the project's vendor folder, then go to
resources/views/vendor/backpack/base and create a file with the exact same name. Backpack\Base will use this new file, instead of the one in the package.
resources/views/vendor/backpack/base/inc/topbar_left_content.blade.php; Backpack will now use this file's contents, instead of
resources/views/vendor/backpack/base/dashboard.blade.phpand Backpack will use that one, instead of the one in the package;
You can create blade views from scratch, or you can use our command to publish the view from the package and edit it to your liking:
php artisan backpack:publish base/dashboard
Then inside the blade files, you can use either plain-old HTML or add dynamic content through Backpack widgets.
If you'll take a look inside any Backpack package, you'll notice the
src directory is organised like a standard Laravel app. This is intentional. It should help you easily understand how the package works, and how you can overwrite/customize its functionality.
When installed, Backpack provides a way for admins to login, recover password and register (don't worry, register is only enabled on
localhost). It does so with its own authentication controllers, models and middleware. If you have regular end-users (not admins), you can keep the user authentication completely separate from admin authentication. You can change which model, middleware classes Backpack uses, inside the
config/backpack/base.php config file.
Backpack uses Laravel's default
App\Usermodel. This assumes you weren't already using this model, or the
userstable, for anything else. Or that you plan to use it for both users & admins. Otherwise, please read below.
If you want to use a different User model than
App\User or you've changed its location, please, you can tell Backpack to use a different model in
config/backpack/base.php instead of the
App\User model that Laravel apps usually have. Look for
If you already use the
users table to store end-users (not admins), you will need a way to differentiate admins from regular users. Backpack does not force one method on you. Here are two methods we recommend, below:
is_admincolumn to your
userstable, then changing the
app/Http/Middleware/CheckIfAdmin::checkIfUserIsAdmin()method to test that attribute exists, and is true;
By default, all administration panel routes will be behind an
/admin/ prefix, and under an
CheckIfAdmin middleware. You can change that inside
Inside your admin controllers or views, please:
This will make sure you're using the model, prefix & middleware that you've defined in
config/backpack/base.php. In case you decide to make changes there later, you won't need to change anything else. There are also other backpack helpers you can use.
When logged in, the admin can click his/her name to go to his "account" page. There, they will be able to do a few basic operations: change name, email or password.
Changing name and email is done inside
Backpack\Base\app\Http\Controllers\Auth\MyAccountController, using the
postAccountInfoForm() methods. If you want to change how this works, we recommend you create a
routes/backpack/base.php file, copy-paste all Backpack\Base routes there and change whatever routes you need, to point to your own controller, where you can do whatever you want.
If you only want to add a few new inputs, you can do that by creating a file in
resources/views/vendor/backpack/base/my_account.blade.php that uses code from the same file in the Backpack package, but adds the inputs you need. Remember to also make these fields
$fillable in your User model.
Password changing is done inside
Backpack\Base\app\Http\Controllers\Auth\MyAccountController. If you want to change how this works, we recommend you create a
routes/backpack/base.php file, copy-paste all Backpack\Base routes there and change whatever you need. You can then point the route to your own controller, where you can do whatever you want.
You can use these helpers anywhere in your app (models, views, controllers, requests, etc), except the config files, since the config files are loaded before the helpers.
backpack_url($path)- Use this helper instead of
url()to generate paths with the admin prefix prepended.
backpack_auth()- Returns the Auth facade, using the current Backpack guard. Basically a shorthand for
\Auth::guard(backpack_guard_name()). Use this instead of
auth()inside your admin panel pages.
backpack_middleware()- Returns the key for the admin middleware. Default is
backpack_authentication_column()- Returns the username column. The Laravel and Backpack default is
backpack_users_have_email()- Tests that the
backpack_avatar($user)- Receives a user object and returns a path to an avatar image, according to the preferences in the config file (gravatar, placeholder or custom).
backpack_guard_name()- Returns the guard used for Backpack authentication.
backpack_user()- Returns the current Backpack user, if logged in. Basically a shorthand for
\Auth::guard(backpack_guard_name())->user(). Use this instead of
auth()->user()inside your admin pages.
When installing Backpack, a few error views are published into
resources/views/errors, if you don't already have other files there. This is because Laravel does not provide error pages for all HTTP error codes. Having these files in your project will make sure that, if a user gets an HTTP error, at least it will look decent. Error pages are provided for the following error codes: