Prepare your Laravel apps incredibly fast, with various commands, services, facades and boilerplates.
Prepare your Laravel apps incredibly fast, with various commands, services, facades and boilerplates.
Grafite has archived this project and no longer supports or develops the code. We recommend using only as a source of ideas for your own code.
Builder - A handful of tools for Rapid Laravel Development This is a set of tools to help speed up development of Laravel apps. You can start an app with various parts prewritten (Users, User Meta, Roles, Teams). And it comes with a powerful FormMaker which can generate form content from tables, and objects. It can generate epic CRUD prototypes rapidly with full testing scripts prepared for you, requiring very little editing. It also provides an elegant Cryptography tool which is URL friendly. Finally it brings along some friends with LaravelCollective as a vendor.
| Laravel Version | Package Tag | Supported |
|---|---|---|
| 5.7.x | 2.5.x | no |
| 5.6.x | 2.4.x | no |
| 5.5.x | 2.3.x | no |
| 5.4.x | 2.2.x | no |
| 5.3.x | 2.0.x - 2.1.x | no |
| 5.1.x - 5.2.x | 1.9.x | no |
Start a new Laravel project:
laravel new {project_name}or
composer create-project laravel/laravel {project_name}Then run the following to add the Grafite Builder
composer require "grafite/builder"Time to publish those assets! Grafite Builder uses CrudMaker and FormMaker which have publishable assets.
php artisan vendor:publishor
php artisan vendor:publish --provider="Yab\CrudMaker\CrudMakerProvider"
php artisan vendor:publish --provider="Yab\FormMaker\FormMakerProvider"You now have Grafite Builder installed. Try out the Starter Kit.
!!! warning "Make sure you followed the getting started instructions!"
Grafite Builder provides an elegant solution for starting an application by building the most basic views, controllers, models and migrations for your application. No need to use the php artisan make:auth because now you can easily start your whole application with this single command:
php artisan grafite:starter!!! tip "BUT, before we do that lets get a few things set up."
In order to make use of the starter kit you will need to modify some files. Check out the modifications below:
Add the following to your app/Http/Kernel.php in the $routeMiddleware array.
'admin' => \App\Http\Middleware\Admin::class,
'permissions' => \App\Http\Middleware\Permissions::class,
'roles' => \App\Http\Middleware\Roles::class,
'active' => \App\Http\Middleware\Active::class,If you don't want to worry about email activation then remove this from the route's middleware array:
'active'Update the App\User::class in: 'config/auth.php' and 'database/factories/UserFactory.php' to this:
App\Models\User::classAdd the following to 'app/Providers/AuthServiceProvider.php' in the boot method
Gate::define('admin', function ($user) {
return ($user->roles->first()->name === 'admin');
});
Gate::define('team-member', function ($user, $team) {
return ($user->teams->find($team->id));
});Add the following to 'app/Providers/EventServiceProvider.php' in the $listen property
'App\Events\UserRegisteredEmail' => [
'App\Listeners\UserRegisteredEmailListener',
],You will want to create an sqlite memory test database in the config/database.php
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],Add the following line to the 'phpunit.xml' file
The Starter kit has an email activation component added to the app to ensure your users have validated their email address.
You can disable it by removing the active middleware from the web routes. You will also have to disable the Notification but it
won't cause any problems if you remove the email activation.
You will also need to set the location of the email for password reminders. (config/auth.php - at the bottom)
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],You may try and start quickly by testing the registration but please make sure your app's email is configured or it will throw an exception.
You can do this in the .env file easily by setting it to 'log' temporarily
MAIL_DRIVER=logOnce you've added in all these parts you will want to run the starter command!
php artisan grafite:starterThen you'll have to refresh the list of all classes that need to be included in the project.
composer dump-autoloadThen you'll need to migrate to add in the users, user meta, roles and teams tables. The seeding is run to set the initial roles for your application.
php artisan migrate --seedOnce you get the starter kit running you can register and login to your app. You can then you can visit the settings section of the app and set your role to admin to take full control of the app.
Grafite Builder updated the basic controllers to handle things like creating a profile when a user is registered, as well as setting default return routes to dashboard etc. It also provides contollers for handling profile modifications and pages, team management etc. The admin controller handles the admin of users, modifying a user provided the user has the admin role.
Grafite Builder overwrites the default middleware due to changes in the redirects. It also provides the Admin middleware for route level protection relative to roles.
There are requests provided for handling the creation of Teams and updating of all components. Here we integrate the rules required that are able to run the validations and return errors. (If you're using Grafite Builder FormMaker Facade then it will even handling accepting the errors and highlighting the appropriate fields.)
Given that there are numerous routes added to handle teams, profiles, password etc all routes are overwritten with the starter kit.
The permissions config file is published, this is a way for you to set access levels and types of permissions Roles can have
The events for various actions.
The event listeners for various actions.
Models are obvious, but when we then integrate Services below which handle all the buisness logic etc which make the calls to the models we implement SOLID practices, the Controller, Console or other Service, which calls the service only accesses the model through it. Once these have been integrated please ensure you delete the User.php model file and ensure that you have followed the installation and config instructions.
These are all our emails that we need to send out to the users in the application. These are amazing since they use the power of Laravel's notifcation component.
Service structure allows us to keep the buisness logic outside of the models, and controllers. This approach is best suited for apps that may wish to integrate an API down the road or other things. It also allows for a highly testable structure to the application.
Please ensure that all migrations and seeds are run post installation. These seeds set the default roles available in your application.
The views consist of as little HTML as possible to perform the logical actions. These are intended to be the most basic, and all of which are intended to be modified.
Grafite Builder starter kit provides the basic unit tests for each of its own parts. This provides some great examples of testing for building an application quickly.
The application dashboard is found by browsing to the /dashboard endpoint. The default admin user login credentials are:
The user model is expanded with Grafite Builder Starter Kit. It adds to the basic user model: roles, teams, and user meta. The relationships are as follows:
It also provides the following methods:
meta() // The relationship method
roles() // The relationship method
hasRole(role_name) // checks if user has role
teams() // The relationship method
isTeamMember(team_id) // checks if user is member
isTeamAdmin(team_id) // checks if user is admin level memberThe Admin middleware acts as a tool for setting admin level permissions on the routes or controller level.
['middleware' => 'admin']This simple addition to a route will ensure the user has access to the admin level, if not it will return them from where they came.
The Active middleware acts checks if the
No open issues yet, or sync has not completed.