- Laravel: http://laravel.com/
- Laravel Zero: http://laravel-zero.com/ (command-line applications)
- October CMS gist: https://gist.github.com/hofmannsven/e71b90092fde4dc5cff9
- Custom Laravel: https://customlaravel.com/
- Laravel cheatsheet: http://cheats.jesse-obrien.ca/
- Laravel 5 cheatsheet: https://aufree.github.io/laravel5-cheatsheet/
- Laravel IDE helper for PhpStorm: https://github.com/barryvdh/laravel-ide-helper
- Composer cheatsheet: https://composerversioncheatsheet.com/
- Performance: https://serversforhackers.com/laravel-perf/
Within ~/.zshrc
:
plugins=(git laravel5)
Show version: php artisan --version
Show all commands: php artisan list
Show all routes: php artisan route:list
Key: php artisan key:generate
<FilesMatch "^\.">
Order allow,deny
Deny from all
</FilesMatch>
Execute a command in the command line with a particular PHP version:
php5.6 artisan list
php7.0 artisan list
php7.1 artisan list
Problem: $ vagrant up
results in authentication failure.
default: Warning: Authentication failure. Retrying...
Solution: SSH into the VM via $ ssh vagrant@localhost -p 2222
and remove and regenerate the private keys:
wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
chown -R vagrant:vagrant .ssh
Install Mcrypt via Homebrew: brew install mcrypt
Install Mcrypt for a particular PHP Version: sudo apt install php5.6-mcrypt
Make sure to grant Apache access to store data within storage
:
storage/app
storage/framework
storage/logs
See: https://gist.github.com/hofmannsven/8392477#permissions
Daily logs: Add APP_LOG=daily
to your .env
config file (see config/app.php
).
Populate: php artisan db:seed
Populate a specific database: php artisan db:seed --database mysql_testing
Create new migration: php artisan make:migration create_tasks_table --create=tasks
» see database/migrations
Migrate: php artisan migrate
Migrate, again: php artisan migrate:refresh
Migrate a specific database: php artisan migrate --database mysql_testing
Create new model: php artisan make:model Task
» see app
Create new model and do migration: php artisan make:model Task -m
Create new policy: php artisan make:policy TaskPolicy
» see app/Policies
Create views: php artisan make:auth --views
» see resources/views/auth
Create: php artisan make:middleware BeforeMiddleware
» see app/Http/Middleware
Note: The name of the event is usally set in past tense (event is already done).
Add new event with listeners in app/Providers/EventServiceProvider.php
Create new events automatically based on your EventServiceProvider
: php artisan event:generate
» see app/Events
and also app/Listeners
Create command: php artisan make:console AppAbout --command=app:about
» see app/Console/Commands
Register new command: » see app/Console/Kernel.php
Usage: php artisan app:about
- PHPUnit cheatsheet: https://gist.github.com/hofmannsven/67deb0d36c991246b0a0
Usage: php artisan make:test UserTest
Add testing database credentials to your phpunit.xml
file:
<env name="DB_HOST" value="192.168.10.10"/>
<env name="DB_DATABASE" value="homestead"/>
<env name="DB_USERNAME" value="homestead"/>
<env name="DB_PASSWORD" value="secret"/>
Use temporary in memory database:
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
Re-generate autoload: composer dump-autoload
List dependencies of all dependencies: composer show --tree
Cache: php artisan route:cache
Clear: php artisan route:clear
Usage: php artisan tinker
E.g. create User: $user = factory(App\User::class)->create();
Composer: composer dump-autoload --optimize
Use controllers instead of closures within routes/web.php
file to cache routes.
Use route:cache
to skip route compilation on each request:
php artisan route:cache
Use config:cache
to reduce configuration parsing:
php artisan config:cache
The config cache includes config files and also the .env
file.
Attention: Make sure to not use env()
anywhere in the code base beside the config files!
env()
will return null
with config:cache
. Use config()
helper function instead.
Generated cache files can be found in: /bootstrap/cache
Use eager loading to avoid the n+1 query problem.
Save database queries using the with()
helper function and reduce the amout of queries made in total.
User::with('relation_attr')->get();
Reduce server memory usage on queries returning lots of data to not overload the server.
Attention: This may increase the database queries and overall loading time!
Use chunk()
helper function in the query builder.
Add index (KEY
) columns based an where
statemants whenever possible as MySQL is quite fast at indexing which will result in faster queries.
Set the debug bar config to explain within /config/debugbar.php
to explain each SELECT
statement:
'explain' => [
'enabled' => true
]
Set multi-column indexes as new migration from database/migrations/add_table_name_indexes.php
:
Schema::table('table_name', function(Blueprint $table) {
$table->index(['user_id', 'created_at']);
});
Use a key-value storage option like Redis or Memcached.
Set Redis drivers within .env
file:
CACHE_DRIVER=redis
SESSION_DRIVER=redis
And require predis
via composer: composer require predis/predis
Make sure to keep an eye on Redis memory usage on user heavy applications and save as litte information as posssbile to Redis to reduce memory usage.
Use and combine auth()->user()->id
and other dynamic parameters to generate a unique cache key with md5()
.
Use the decorator pattern when adding caching to the app.