A flying start for Laravel projects.
A flying start for Laravel projects., (*1)
There were some things that I did/used with new Laravel projects, so putting those things in a package speeds up that process. Maybe you'll find it useful as well. This package is in the public domain (using the Unlicense), so go ahead and use it for anything., (*2)
The intended Laravel version is 5.6, I haven't tested it in previous versions., (*3)
Include this project with Composer:
composer require nerbiz/embark 0.*
, (*4)
The service provider will be autodiscovered, but for completeness, the service provider file is Nerbiz\Embark\EmbarkServiceProvider
. There is no (need for a) Facade, but who knows what the future brings., (*5)
Publish the config file:
php artisan vendor:publish --tag=embark-config
, (*6)
Publish some basic views:
php artisan vendor:publish --tag=embark-views
, (*7)
Publish stubs, in case you'd like to customize them:
php artisan vendor:publish --tag=embark-stubs
For convenience, the 'stubs_path' value in config/embark.php
already points to where the stubs are published., (*8)
These are the Artisan commands included in this package:, (*9)
embark:empty-class
: Creates an empty class with only a constructor. The namespace for it can be configured in config/embark.php
.embark:migration
: Works in the same way as (extends) make:migration
, but uses custom stubs, which use the custom Blueprint of this package.embark:model
: Works in the same way as (extends) make:model
, but uses custom namespace and embark:migration instead of make:migration. The namespace for it can be configured in config/embark.php
.embark:models-namespace
: Create the App\Models namespace and move User to it, and update files that use the User model. Namespace name can be defined in config/embark.php
.embark:restructure
: Adjusts the directory structure, creates a 'laravel' directory next to the public directory.embark:webpack
: Intended to use with embark:restructure
, this overwrites the webpack.mix.js file, using the new public directory path.Explanation for embark:restructure
:
I guess this is mostly useful for shared hosting, or other environments with limited control., (*10)
Usually, the public directory is called 'public_html', not 'public' as in Laravel. There are usually also a number of files and directories next to the public directory, like things for stats, FTP, SSH, mailboxes etc. I don't prefer to mix those with Laravel files, so my idea was to move all those files to a separate 'laravel' directory. The end result is a 'laravel' and 'public_html' directory, next to each other., (*11)
Paths have also been taken care of in this command, so you can just start building., (*12)
In a migration file, replace these use statements:, (*13)
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint;
With these:, (*14)
use Nerbiz\Embark\Facades\Schema; use Nerbiz\Embark\Schema\Blueprint;
Then you can use $table
as usual, but the foreignKey()
method has been added.
foreignKey()
works the same as foreign()
, but it adds ->references(...)->on(...)->onUpdate(...)->onDelete(...)
implicitly. For example: category_id implicitly references id on categories. The default onUpdate and onDelete values are set in config/embark.php
., (*15)
Since this method returns a Fluent instance, you can use it as you would otherwise. Therefore you could for instance overwrite an implicit foreign table name: $table->foreignKey('category_id')->on('product_categories');
, (*16)
My intention is to expand the custom Blueprint with more useful methods., (*17)
Please do a pull request, if you have some improvements in mind., (*18)
This project uses the Unlicense., (*19)