-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework and upgrade project to Laravel 9
- Loading branch information
1 parent
69b7f4f
commit 5d9bca0
Showing
284 changed files
with
12,427 additions
and
5,356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,24 @@ APP_DEBUG=true | |
APP_URL=http://localhost | ||
|
||
LOG_CHANNEL=stack | ||
LOG_DEPRECATIONS_CHANNEL=null | ||
LOG_LEVEL=debug | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
DB_USERNAME=root | ||
DB_PASSWORD= | ||
|
||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=file | ||
FILESYSTEM_DISK=local | ||
QUEUE_CONNECTION=sync | ||
SESSION_DRIVER=file | ||
SESSION_LIFETIME=120 | ||
QUEUE_DRIVER=sync | ||
|
||
MEMCACHED_HOST=127.0.0.1 | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
|
@@ -29,13 +34,21 @@ MAIL_PORT=2525 | |
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
MAIL_FROM_ADDRESS="[email protected]" | ||
MAIL_FROM_NAME="${APP_NAME}" | ||
|
||
MAIL_FROM_ADDRESS= | ||
MAIL_FROM_NAME= | ||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_BUCKET= | ||
AWS_USE_PATH_STYLE_ENDPOINT=false | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_APP_KEY= | ||
PUSHER_APP_SECRET= | ||
PUSHER_HOST= | ||
PUSHER_PORT=443 | ||
PUSHER_SCHEME=https | ||
PUSHER_APP_CLUSTER=mt1 | ||
|
||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,96 @@ | ||
# saas-boilerplate | ||
This is a SaaS boilerplate built on top of the Laravel framework. | ||
|
||
This is a SaaS boilerplate built on top of the Laravel framework. | ||
Built to provide developers with a template to kickoff their SaaS application, | ||
without the hustle for repetitive tasks such as user account setup, subscriptions | ||
without the hustle for repetitive tasks such as user account setup, subscriptions | ||
and role management. | ||
|
||
## features | ||
|
||
- Authentication | ||
- Login / Registration | ||
- Email Activation | ||
- Two Factor Login (only when enabled) | ||
- Login / Registration | ||
- Email Activation | ||
- Two Factor Login (only when enabled) | ||
- Subscription with Stripe | ||
- User plans | ||
- Team plans | ||
- User plans | ||
- Team plans | ||
- Account (User Account) | ||
- Profile Update | ||
- Change Password | ||
- Two Factor Authentication | ||
- Subscription | ||
- Cancel Subscription | ||
- Resume Subscription | ||
- Swap Plan | ||
- Update Card | ||
- API Tokens | ||
- Profile Update | ||
- Change Password | ||
- Two Factor Authentication | ||
- Subscription | ||
- Cancel Subscription | ||
- Resume Subscription | ||
- Swap Plan | ||
- Update Card | ||
- API Tokens | ||
- Single Database Multi-tenancy | ||
- Admin | ||
- User Management | ||
- Manage User Roles | ||
- Role & Permissions Management | ||
- User Management | ||
- Create Users (and assign role) | ||
- Manage User Roles | ||
- Role & Permissions Management | ||
- Developer Panel | ||
- Manage OAuth Clients | ||
- Manage Personal Access Tokens | ||
- Manage OAuth Clients | ||
- Manage Personal Access Tokens | ||
- Other features | ||
- Filtering (extendable) | ||
- API access (starter template) | ||
- Filtering (extendable) | ||
- API access (starter template) | ||
|
||
*Note: Some features may be subjected to change. Other features may not be listed | ||
since they are under development or do not qualify as a standard / main SaaS feature. | ||
*Note: Some features may be subjected to change. Other features may not be listed | ||
since they are under development or do not qualify as a standard / main SaaS feature. | ||
Some common features will not be listed as well.* | ||
|
||
## installation | ||
|
||
1. Fork, clone or download this repository. | ||
2. Run `composer install` if its the initial setup or `composer update`. | ||
3. Setup your environment keys in .env | ||
3. Setup your environment keys in .env | ||
(*If .env does not exist then copy / rename .env.example as .env*) | ||
4. Run `php artisan app:name` to set the name (namespace) of your app. | ||
(*Remember not to live any spaces*) | ||
5. Run `php artisan migrate` for initial tables setup. | ||
6. __Optional:__ Run `php artisan db:seed --class=RoleTableSeeder` to set the initial | ||
4. Run `php artisan migrate` for initial tables setup. | ||
5. __Optional:__ Run `php artisan db:seed --class=RoleTableSeeder` to set the initial | ||
roles and permissions, then follow `step 7` below to assign a user the initial permissions and roles. | ||
7. __Optional:__ To create a `super / root` admin; | ||
Run `php artisan admin:assign-role [email protected] admin-root`. | ||
Substitute `[email protected]` with an existing user email. `admin-root` is the __default root Admin role__. | ||
|
||
__Note:__ You must follow `step 6` above first to setup the root admin. | ||
6. __Optional:__ To create a `super / root` admin; | ||
Run `php artisan role:assign [email protected] admin-root`. | ||
Substitute `[email protected]` with an existing user email. `admin-root` is the __default root Admin role__. | ||
|
||
__Note:__ You must follow `step 5` above first to setup the root admin. | ||
|
||
## usage | ||
|
||
### Custom Commands | ||
1. __Admin: _Assign user a role___ | ||
- Use `php artisan admin:assign-role <email> <role-slug>`: | ||
`<email>` is the user's email and `<role-slug>` is the _slug of the role_ you wish to assign the user. | ||
|
||
1. __Admin: *Assign user a role*__ | ||
- Use `php artisan role:assign <email> <role-slug>`: | ||
`<email>` is the user's email and `<role-slug>` is the *slug of the role* you wish to assign the user. | ||
|
||
### Force HTTPS | ||
When pushing the project to a platform or production environment, | ||
|
||
When pushing the project to a platform or production environment, | ||
assets or urls may be broken if the platform enforces HTTPS. | ||
|
||
To enable urls to use HTTPS: | ||
|
||
Set `FORCE_HTTPS` variable in `.env` file to `true`. | ||
*To enable urls to use HTTPS:* | ||
|
||
Set `FORCE_HTTPS` variable in `.env` file to `true`. | ||
|
||
By default `FORCE_HTTPS` is `false`. | ||
|
||
```Note: ``` If `FORCE_HTTPS` does not exist in your `.env`, | ||
```Note:``` If `FORCE_HTTPS` does not exist in your `.env`, | ||
just add it as a new variable and assign a boolean value `true` or `false`. | ||
|
||
This dynamically tells Laravel to force urls to use HTTPS which is especially | ||
This dynamically tells Laravel to force urls to use HTTPS which is especially | ||
handy in fixing or preventing broken assets urls. | ||
|
||
### Single Database Multi-tenancy | ||
|
||
See [miracuthbert/laravel-multi-tenancy](https://github.com/miracuthbert/laravel-multi-tenancy) | ||
|
||
#### Model setup | ||
|
||
To start using single databse multi-tenancy call `ForTenants` trait on a model | ||
|
||
```php | ||
use SAASBoilerplate\App\Tenant\Traits\ForTenants; | ||
use Miracuthbert\Multitenancy\Traits\ForTenants; | ||
|
||
class Project extends Model | ||
{ | ||
|
@@ -90,7 +99,8 @@ class Project extends Model | |
``` | ||
|
||
#### Tenants CRUD Operations | ||
Once you have setup the model as show above. `Just call CRUD operations directly`. | ||
|
||
Once you have setup the model as show above. `Just call CRUD operations directly`. | ||
`Tenant` relationships are handled automatically. | ||
|
||
```php | ||
|
@@ -101,38 +111,51 @@ $projects = Project::get(); | |
``` | ||
|
||
#### Normal CRUD Operations | ||
To perform CRUD operations on models with `ForTenants` trait can be done by | ||
|
||
To perform CRUD operations on models with `ForTenants` trait can be done by | ||
adding `withoutForTenants` scope when fetching records associated with that model. | ||
|
||
```php | ||
$projects = Project::withoutForTenants()->get(); | ||
``` | ||
|
||
***This comes in handy for example in: admin or moderation operations*** | ||
*__This comes in handy for example in: admin or moderation operations__* | ||
|
||
#### Routing | ||
|
||
All `tenant` routes are under the routes folder in the `tenant.php` file. | ||
|
||
Note: ***Tenant routes follow the same structure as other routes*** | ||
Note: *__Tenant routes follow the same structure as other routes__* | ||
|
||
`The main reason we place all tenant routes separately is to handle route binding and | ||
its much easier to know which routes are for tenants.` | ||
|
||
## libraries & packages | ||
|
||
- Main | ||
- PHP (>=7.1.3) | ||
- Laravel (Minimal 5.6) | ||
- Laravel Cashier (can be switched) | ||
- PHP (>=8) | ||
- Laravel (Minimal 9) | ||
- Laravel Cashier (can be switched) | ||
- UI (can be switched) | ||
- Bootstrap (v4) | ||
- Font awesome | ||
- Simple Line Icons | ||
- jQuery | ||
- VueJs | ||
- Development | ||
- nodejs | ||
- npm | ||
- Bootstrap (v4) | ||
- Font awesome | ||
- Simple Line Icons | ||
- jQuery | ||
- VueJs | ||
- Development | ||
- nodejs | ||
- npm | ||
|
||
## services | ||
|
||
- Stripe (payment gateway) | ||
- Authy by Twilio (two factor authentication) | ||
- Authy by Twilio (two factor authentication) | ||
|
||
## Changes | ||
|
||
- `Roles and Permissions`: See [miracuthbert/laravel-roles](https://github.com/miracuthbert/laravel-roles) | ||
- `Multi-tenancy`: See [miracuthbert/laravel-multi-tenancy](https://github.com/miracuthbert/laravel-multi-tenancy) | ||
|
||
## Security Vulnerabilities | ||
|
||
If you discover a security vulnerability, please send an e-mail to Cuthbert Mirambo via [[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace SAAS\App\Actions\Fortify; | ||
|
||
use Illuminate\Support\Arr; | ||
use Illuminate\Validation\Rule; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Validator; | ||
use SAAS\Domain\Users\Models\Role; | ||
use SAAS\Domain\Users\Models\User; | ||
use Laravel\Fortify\Contracts\CreatesNewUsers; | ||
use Illuminate\Auth\Events\Registered; | ||
|
||
class CreateNewUser implements CreatesNewUsers | ||
{ | ||
use PasswordValidationRules; | ||
|
||
protected $defaults = [ | ||
'password' => 'password', | ||
'confirmation_password' => 'password', | ||
]; | ||
|
||
/** | ||
* Validate and create a newly registered user. | ||
* | ||
* @param array $input | ||
* @param array $except | ||
* @param bool $fireEvent | ||
* @return \SAAS\Domain\Users\Models\User | ||
*/ | ||
public function create(array $input, $except = [], $fireEvent = false) | ||
{ | ||
$input = array_merge($input, Arr::only($this->defaults, $except)); | ||
|
||
Validator::make($input, Arr::except([ | ||
'first_name' => 'required|string|max:30', | ||
'last_name' => 'required|string|max:30', | ||
'username' => 'nullable|string|max:30|unique:users', | ||
'email' => [ | ||
'required', | ||
'string', | ||
'email', | ||
'max:255', | ||
Rule::unique(User::class), | ||
], | ||
'password' => $this->passwordRules(), | ||
'terms' => 'required' | ||
], $except))->validate(); | ||
|
||
return DB::transaction(function () use ($input, $fireEvent) { | ||
return tap(User::create([ | ||
'first_name' => $input['first_name'], | ||
'last_name' => $input['last_name'], | ||
'username' => $input['username'], | ||
'email' => $input['email'], | ||
'password' => Hash::make($input['password']), | ||
]), function (User $user) use($input, $fireEvent) { | ||
if ($fireEvent) { | ||
$this->fireEvent($user, $fireEvent); | ||
} | ||
$this->assignRole($user, $input['role_id'] ?? null); | ||
}); | ||
}); | ||
} | ||
|
||
public function fireEvent(User $user, $fireEvent = false) | ||
{ | ||
event(new Registered($user)); | ||
} | ||
|
||
public function assignRole(User $user, $roleId) | ||
{ | ||
if ($roleId && ($role = Role::find($roleId))) { | ||
$user->assignRole($role); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace SAAS\App\Actions\Fortify; | ||
|
||
use Laravel\Fortify\Rules\Password; | ||
|
||
trait PasswordValidationRules | ||
{ | ||
/** | ||
* Get the validation rules used to validate passwords. | ||
* | ||
* @return array | ||
*/ | ||
protected function passwordRules() | ||
{ | ||
return ['required', 'string', new Password, 'confirmed']; | ||
} | ||
} |
Oops, something went wrong.