Laravel Snippets

Creation

Required Packages:

  • php-mbstring
  • php-dom

With Backpack (https://backpackforlaravel.com/):

composer create-project --prefer-dist laravel/laravel PROJECTNAME

cd PROJECTNAME

git init

cp .env.example .env
# EDIT .env ; DB!

php artisan cache:clear
php artisan config:cache

composer require backpack/crud
php artisan backpack:base:install
php artisan backpack:crud:install

To add vendor to git: (optional!)

sed -i 's;/vendor;;' .gitignore

To disable Register for admins and add middleware to admin panel

  • Add changes from .env.example to .env

curl -o LaravelBackpack_IsAdmin.patch https://kb.kiwi/file/01802fca038c38aa00f0fcbf2d9cd1f1
git apply LaravelBackpack_IsAdmin.patch
rm -f LaravelBackpack_IsAdmin.patch

Create CRUD for User:

# If Other Models:
php artisan make:migration create_users_table
php artisan migrate

php artisan backpack:crud user
php artisan backpack:base:add-custom-route "CRUD::resource('user', 'UserCrudController');"
php artisan backpack:base:add-sidebar-content "<li><a href='{{ backpack_url('user') }}'><i class='fa fa-user'></i> <span>Users</span></a></li>"