This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
731 additions
and
1,052 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
|
||
php: | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer update --prefer-source --no-interaction --dev | ||
|
||
script: | ||
- vendor/bin/phpunit -v --coverage-text --colors=never --stderr |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) <Nasrul Hazim> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,37 +1,217 @@ | ||
# Web Application Boilerplate | ||
[](https://travis-ci.org/cleaniquecoders/laravel-boilerplate) [](https://packagist.org/packages/cleaniquecoders/laravel-boilerplate) [](https://packagist.org/packages/cleaniquecoders/laravel-boilerplate) [](https://packagist.org/packages/cleaniquecoders/laravel-boilerplate) | ||
|
||
A boilerplate to speed up development. | ||
# Laravel Boilerplate | ||
|
||
# Installation | ||
A boilerplate based on Laravel Framework to speed up web application development setup. | ||
|
||
## Packages | ||
|
||
1. [Cleanique Coders](https://github.com/cleaniquecoders) | ||
|
||
- Artisan Makers | ||
- Blueprint Macro | ||
- Profile | ||
|
||
2. [Laravel Proxy Package](https://github.com/fideloper/TrustedProxy) | ||
3. [Spatie](https://github.com/spatie) | ||
|
||
- Image Optimizer | ||
- Laravel Activitylog | ||
- Laravel Analytics | ||
- Laravel Collection Macros | ||
- Laravel Google Calendar | ||
- Laravel Html | ||
- Laravel Medialibrary | ||
- Laravel Menu | ||
- Laravel Permission | ||
- Laravel Referer | ||
- Laravel Responsecache | ||
- Laravel Sluggable | ||
|
||
4. [Hashids](https://github.com/ivanakimov/hashids.php) | ||
5. [Sweet Alert](https://github.com/uxweb/sweet-alert) | ||
6. [Sempro PHPUnit Pretty Printer](https://github.com/Sempro/phpunit-pretty-print) | ||
|
||
## Installation | ||
|
||
``` | ||
$ composer create-project osinitiative/web-app-boilerplate your-project-name "1.0.1" | ||
$ composer create-project cleaniquecoders/laravel-boilerplate | ||
``` | ||
|
||
# Packages | ||
|
||
Most of the packages from Spatie. | ||
Configure your `.env`, then: | ||
|
||
1. Laravel Permission | ||
2. Laravel Media Library | ||
3. Laravel Activity | ||
4. Laravel Newsletter | ||
5. Laravel Analytics | ||
6. Laravel Response Cache | ||
7. Laravel Sluggable | ||
8. Laravel Menu | ||
9. Laravel Collection Macros | ||
10. Laravel Google Calendar | ||
11. Laravel Html | ||
12. Image Optimizer | ||
``` | ||
$ php artisan reload:db | ||
``` | ||
|
||
# Google API | ||
### Google API | ||
|
||
Create [Google Service Account Credentials](https://console.developers.google.com/apis/dashboard?project=karnival-usahawan-desa) for: | ||
|
||
1. [Google Calendar](https://github.com/spatie/laravel-google-calendar#how-to-obtain-the-credentials-to-communicate-with-google-calendar) | ||
2. [Google Analytic](https://github.com/spatie/laravel-analytics#how-to-obtain-the-credentials-to-communicate-with-google-analytics) | ||
|
||
# TODO | ||
## Usage | ||
|
||
### Commands | ||
|
||
There's some commands area ready built-in. Others, may refer to respective packages. | ||
|
||
- `reload:db` - Run `migrate:fresh --seed` with `profile:seed`. You may extend the usage. | ||
- `reload:cache` - Recache everything | ||
|
||
### Helpers | ||
|
||
**generate_sequence($count)** | ||
|
||
Generate sequence with leading zero like `000001`, `000002` and so on. | ||
|
||
Length for the leading zero can be configure in `.env` file - `DOCUMENT_SEQUENCE_LENGTH`. | ||
|
||
**abbrv($word, $unique_characters)** | ||
|
||
A helper to create abbreviation by removing non-alphanumeric, vowels. | ||
|
||
Passing second argument as false will return non-unique characters - means that you will see repeatative characters. | ||
|
||
Following are the sample usage and output: | ||
|
||
``` | ||
>>> abbrv("Cleanique Coders") | ||
=> "CLNQDRS" | ||
>>> abbrv("Cleanique Coders", false) | ||
=> "CLNQCDRS" | ||
``` | ||
|
||
**generate_reference($prefix, $count)** | ||
|
||
Generate document reference string. Usually a document have their own reference on the particular date event. | ||
|
||
For instance a payslip document have a reference number / string like `CCR/PYSL/2018/01/000001`. | ||
|
||
The format generate is `abbrv/Year/Month/Date/reference_id`. | ||
|
||
You can use in two ways: | ||
|
||
``` | ||
>>> generate_reference("Cleanique Coders Payroll") | ||
=> "CLNQ/CDRS/PYRL/2018/02/04/TBIPOU" | ||
>>> generate_reference("Cleanique Coders Payroll", 10) | ||
=> "CLNQ/CDRS/PYRL/2018/02/04/000010" | ||
``` | ||
|
||
The length of the `TBIPOU` or `000010` is depends on `DOCUMENT_SEQUENCE_LENGTH` in `.env` file. | ||
|
||
**hashids($salt, $length, $alphabet)** | ||
|
||
It's essential to have important resources to use other than just incremental id. One of the option is to use [Hashids](https://github.com/ivanakimov/hashids.php). | ||
|
||
Following are an example how to use the helper. | ||
|
||
``` | ||
>>> hashids()->encode(1) | ||
=> "yR5ajG4DBwlz" | ||
>>> hashids('random-salt')->encode(1) | ||
=> "WZvoOMBr19YN" | ||
>>> hashids('random-salt', 24)->encode(1) | ||
=> "GPz1W4mLavAeqAwB2XZbOgQn" | ||
>>> hashids('random-salt', 6)->encode(1) | ||
=> "5qy0lP" | ||
>>> hashids('random-salt', 6, 'qwertyuiopasdfghjkl')->encode(1) | ||
=> "orgpqe" | ||
>>> hashids('random-salt', 6, ',./;<>?:"{}|[]\-=`~!@#$%^&*()')->encode(1) | ||
=> "{&(^&-" | ||
>>> hashids('random-salt', 12, ',./;<>?:"{}|[]\-=`~!@#$%^&*()')->encode(1) | ||
=> "~-!\`-&(*[{)" | ||
``` | ||
|
||
For `$salt`, by default it will use `APP_KEY`, but you may override it by passing the salt name at the first argument. | ||
|
||
For `$length`, you can pass any length of hashids you want to create. By default it's 12 characters. | ||
|
||
For `$alphabet`, you can put any characters as per example above. But remember, the alphabets need to be minimum of **16 characters**. | ||
|
||
**str_slug_fqcn($object)** | ||
|
||
Return slug name for given object. | ||
|
||
``` | ||
>>> $user = \App\Models\User::first(); | ||
=> App\Models\User {#1013 | ||
id: 1, | ||
hashslug: "krOErpkv6EVR", | ||
slug: "elza-bins", | ||
name: "Elza Bins", | ||
email: "kautzer.polly@example.com", | ||
deleted_at: null, | ||
created_at: "2018-02-04 03:11:07", | ||
updated_at: "2018-02-04 03:11:07", | ||
} | ||
>>> str_slug_fqcn($user) | ||
=> "app-models-user" | ||
``` | ||
|
||
**audit($model, $message, $causedBy)** | ||
|
||
Simply record audit trail on given `$model`, with proper `$message`. You can optionally passed the third argument - `$causedBy`. | ||
|
||
``` | ||
>>> auth()->loginUsingId(1) | ||
>>> $user = \App\Models\User::first(); | ||
>>> audit($user, 'access via terminal') | ||
>>> auth()->user()->activity->toArray() | ||
=> [ | ||
[ | ||
"id" => 4, | ||
"log_name" => "default", | ||
"description" => "User successfully logged in.", | ||
"subject_id" => 1, | ||
"subject_type" => "App\Models\User", | ||
"causer_id" => 1, | ||
"causer_type" => "App\Models\User", | ||
"properties" => Illuminate\Support\Collection {#971 | ||
all: [], | ||
}, | ||
"created_at" => "2018-02-04 03:18:50", | ||
"updated_at" => "2018-02-04 03:18:50", | ||
], | ||
[ | ||
"id" => 5, | ||
"log_name" => "default", | ||
"description" => "access via terminal", | ||
"subject_id" => 1, | ||
"subject_type" => "App\Models\User", | ||
"causer_id" => 1, | ||
"causer_type" => "App\Models\User", | ||
"properties" => Illuminate\Support\Collection {#980 | ||
all: [], | ||
}, | ||
"created_at" => "2018-02-04 03:19:16", | ||
"updated_at" => "2018-02-04 03:19:16", | ||
], | ||
] | ||
``` | ||
|
||
## Test | ||
|
||
To run the test, type `vendor/bin/phpunit` in your terminal. | ||
|
||
To have codes coverage, please ensure to install PHP XDebug then run the following command: | ||
|
||
``` | ||
$ vendor/bin/phpunit -v --coverage-text --colors=never --stderr | ||
``` | ||
|
||
## Contributions | ||
|
||
Everyone are welcome to contribute to this package. However, it's a good practice to provide: | ||
|
||
1. The problem you solved | ||
2. Provide test | ||
3. Documentation | ||
|
||
Without these 3, you may add extra work for the maintainer. | ||
|
||
## License | ||
|
||
1. Media Library for User | ||
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). |
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,46 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class ReloadCacheCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'reload:cache'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Reload all caches'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->call('cache:clear'); | ||
$this->call('config:cache'); | ||
$this->call('responsecache:flush'); | ||
$this->call('route:cache'); | ||
$this->call('view:clear'); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class ReloadDbCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'reload:db'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Reload Database'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->call('migrate:fresh', ['--seed' => true]); | ||
$this->info('Seeding Profile Dependencies'); | ||
$this->call('profile:seed'); | ||
} | ||
} |
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
Oops, something went wrong.