Scaffold Overview
Grafite Scaffold provides an elegant solution for starting an application by having the most basic views, controllers, models, migrations, packages and other features built in advance. It is a fine tuned boilerplate for any client application you may need to develop. Below we'll cover all the basic additions that are not part of a fresh Laravel application.
PHP Code
Dependencies
Please consult documentation related to these packages if you wish to work with their functionality.
grafite/auth
grafite/charts
grafite/database
grafite/forms
grafite/html
grafite/support
intervention/image
laravel/cashier
laravel/helpers
lasserafn/php-initial-avatar-generator
tightenco/ziggy
Charts
ActivityThirtyDays
Builds a chartJS driven chart showing the count of all user activity of the course of 30 days. The chart is visible in the Admin Dashboard.
RegistrationThirtyDays
Builds a chartJS driven chart showing the count of all user registrations of the course of 30 days. The chart is visible in the Admin Dashboard.
Exceptions
Handler
We made some modifications to the Exception handler allowing us to enforce JSON responses from API calls, as well as a general error page for exceptions not caught by the error number pages.
Helpers
ActivityHelper
The activity helper is in place to call anywhere in your application that you want to log a user activity.
NotificationHelper
We added notification helpers in order to avoid writing multiple lines of code for every app notification and email notification
UserInterfaceHelper
The primary benefit of the UserInterfaceHelper was having a place to put the method for helping determine which route links should be highlighted as active.
Controllers
In general all controllers added are kept to a minimum. We opted to section the scaffold app with API and Ajax controller directories. This is because the API in this app uses the API auth, and has the intention of being external. Given that we have various axios calls in the Vue components, and since those use the standard Laravel auth, it felt more natural to title them as Ajax implying their internal app nature.
DashboardController
The dashboard controller is the most basic one, after login its the general home page for the application.
InvitesController
The invites controller handles the revoking and resending of invites, the sending of invites is performed by the InviteService
PagesController
The pages controller is intended for general app pages like terms of service and contact.
TeamMembersController
Team members controller handles the basic CRUD pages of a team member including: show, edit, update.
WebhookController
This is an extention of the Cashier webhook controller setting the redirect of a successful payment.
Admin
All Admin level controllers require having the admin
role.
DashboardController
The Dashboard controller loads the charts mentioned above for a basic overview of the app user state in the admin dashboard.
RoleController
A CRUD controller for the application roles and permissions. Permissions are defined in the permissions config file, but roles are dynamic.
UserController
A CRUD controller for app Users. When editing a user the Admin will be able to see their activity records and be able to login as them, for testing purposes etc.
Ajax
Ajax controllers are intended to handle any type of ajax calls within the application since they use the standard Laravel auth.
ApiTokenController
The API token controller handles the reset of a user's API token.
BillingController
The billing controller takes care of the creating and updating of payment methods for subscriptions.
CookiePolicyController
The cookie policy controller handles the acceptance of the cookie policy for a user.
NotificationsController
The notifications controller has the notification count for a user which is what lets us show the count of notifications in the navigation bar.
API
Using Laravel's basic auth for the API lets us have users create an encrypted token.
ApiController
This is a base controller for the API. It handles setting a user
property coming from the Laravel basic auth.
UsersController
The users controller handles getting a users info, updating it, and deleting the user model.
Auth
Nearly all auth controllers in Scaffold are the standard ones from a fresh Laravel app.
RegisterController
There are two main modifications here, one sets the newly created user's role. The other hanldes the registration via invites.
RegisterViaInvites
Registraton via invites handles the landing page provided by the invitation link as well as its validation method.
User
BillingController
The billing controller contains all get routes for elements pertaining to billing. It also contains the coupon methods and invoice getters.
DestroyController
This controller is a dedicated delete controller for the user.
InvitesController
The invites controller handles all aspects of user invites including: listing, accepting and rejecting.
NotificationsController
Handles the CRUD of in app notifications.
SecurityController
Handles the password updating for a given user.
SettingsController
For updating user settings.
TeamsController
Handles Team CRUD elements relative to how a user would own a team.
Forms
Scaffold uses the Grafite Form Maker so you can easily manage app forms via PHP Form Classes.
AdminUserForm
The form for when admin's manage users.
InviteUserForm
The base form for inviting users.
RoleForm
The role CRUD form.
TeamForm
The team CRUD form.
TeamInviteForm
The base form for inviting people to teams.
TeamMemberForm
The team member CRUD form.
UserForm
The user CRUD form.
UserSecurityForm
The user password update form.
Fields
ToggleField
The toggle field sets the checkbox attributes enabling it to work with bootstrap4-toggle.
Middleware
There are a few custom middleware classes added, and most revolve around roles and permissions.
Activity
The activity middleware will log a request as an activity for a user. This can be overkill for some apps, so feel free to remove it from the web routes.
Admin
The admin middleware checks if the user has the admin role.
Permissions
Permissions middleware requires a permission key, and then checks if the user accessing the route has the permission based on their role.
Roles
Roles middleware is the same as admin in that it checks for the user's role and confirms or rejects the request.
Subscription
Subscription middleware confirms that the user has an active subscription before proceeding.
Requests
Most requests simply use the corresponding model's rules.
AdminUserUpdateRequest
Authorization requires admin role and sets the rules.
ApiUserUpdateRequest
Confirms the user is authorized by the API basic auth.
PasswordUpdateRequest
Confirms matching passwords.
TeamCreateRequest
Follows rules relevant to teams
TeamUpdateRequest
Follows rules relevant to teams
UserUpdateRequest
Confirms user is logged in and sets rules for email, name and avatar.
Resources
UserResource
The user resource is used for setting the visible
attributes of a user for access in JavaScript code via Vue Components etc.
Models
Activity
The activity model.
Invite
The invite model.
Role
The role model.
Team
The team model.
User
The user model.
Concerns
HasActivity
Has activites contains the activities relationship.
HasPermissions
The has permissions trait contains the attribute setter for permissions. This is the method which scans the user roles and collects the permissions that are applicable to the user.
HasRoles
The roles trait contains the relationships of roles to the model.
HasSubscription
The subscription trait contains extra methods pertaining to active vs cancelled subscriptions as well as the subscriptionPlan
method.
HasTeams
This trait contains the teams relationship (teams the user owns) and team memberships (teams the user is a memeber of).
Invitable
The invitable trait contains the invites relationship and the invite
creation method itself.
DatabaseSearchable
The database searachable trait provides a simple search method which creates a query to look at each field of the model and search for the keyword. This is a simple use case tool, which when scale calls for it we recommend replacing with laravel/scout
.
Notifications
InAppNotification
The in app notifications is a handy notification to create a notification in the database, which the user can mark as read, or delete.
StandardEmail
When using the standard email notification the end user gets a standard email. This basic email has a subjhect
, greeting
, message
and a login button.
InviteUserEmail
The invite user email has a basic email but it includes a token for account activation and message for the user's invite.
Services
ActivityService
The activity service handles extracting the key data points from the requests in order to log them into the activities table.
InviteService
The invite service handles the creation of invites and the validation of invites.
TeamService
The team services handles the basic CRUD actions of a team as well as leaving, adding and removing members. This service handles things like sending out extra notifications and the authorizing of these actions.
JavaScript Code
Dependencies
Please consult documentation related to these packages if you wish to work with their functionality.
@dashboardcode/bsmultiselect
@grafite/helpers
animate.css
bootstrap
bootstrap4-toggle
vue-clipboards
vue-cookie-law
vue-snotify
JavaScript Components
sidebar
The sidebar quite literally handles the sidebar hiding and revealing based on the size of the window.
subcription-create
Handles the create subcription request handling for Stripe integration.
subcription-payment-method
Handles the changing of the payment method for Stripe integration.
Vue Components
api-token
The API token provides a disabled input field with the current user token when its reset. Scaffold by default encrypts tokens so they're only visible after resetting them. Afterward they are no longer visible.
cookie-law
The cookielaw
component handles a basic footer popup that indicates the app uses cookies. This can be customized as needed.
copy-button
The copy button accepts a message argument for what in fact will be copied when the button is clicked.
modal
A handy modal which can be used anywhere in the app that you have a form submission to draw a modal on screen with a message. It uses window.confirmation(this, "message")
to trigger it. For example:
<button type="submit" onSubmit="confirmation(event, 'this is a modal')">Submit</button>
notification-badge
The notification badge vue component provides a number of the unread messages for the in app notfications
notification-marker
The notification marker vue component provides a color marker indicating that the user should click on their notifications link.
session
The session vue component integrates with Snotify handling notifications on requests. If the request or redirect comes with a message
or errors
this vue component will trigger Snotify.