Laravel Tips
Models
Add user via CLI
Adding a new user manually to database using tinker
command. via: https://stackoverflow.com/questions/35753951/manually-register-a-user-in-laravel
Use php artisan tinker
and enter the following code:
Enabling UUID for models
Enabling UUID for model (v6 tested) -- uses \Illuminate\Support\Str::uuid
Migrations
Add UUID (or swap bigIncrement) and make sure to set as primary column:
When using the column as a foreign key in a pivot table, create a UUID column and do the same foreign key assignment:
Model
- Create a trait to add to models:
app/Traits/Uuids.php
Then "use" that trait in your model:
app/Events.php
- Cast UUID as string inside model (or you'll get errors from foreign keys failing, or UUIDs cast as tiny integers that resemble classic IDs). Reference
app/YourModel.php
Blade
VSCode - Enable emmet autocomplete for Blade syntax
Add to VSCode settings JSON. via
Mass Insert or Update
Mass (bulk) insert or update on duplicate for Laravel 4/5
CLI Commands
Make New View
Command to make blade views using php artisan make:view your.view.name
.
php artisan make:command MakeViewCommand
Add the following to the file:
App\Console\Commands\MakeViewCommand.php
- Register command in console Kernel:
app\Console\Kernel.php