|
1 | | -# Web Application Boilerplate |
| 1 | +[](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) |
2 | 2 |
|
3 | | -A boilerplate to speed up development. |
| 3 | +# Laravel Boilerplate |
4 | 4 |
|
5 | | -# Installation |
| 5 | +A boilerplate based on Laravel Framework to speed up web application development setup. |
| 6 | + |
| 7 | +## Packages |
| 8 | + |
| 9 | +1. [Cleanique Coders](https://github.com/cleaniquecoders) |
| 10 | + |
| 11 | + - Artisan Makers |
| 12 | + - Blueprint Macro |
| 13 | + - Profile |
| 14 | + |
| 15 | +2. [Laravel Proxy Package](https://github.com/fideloper/TrustedProxy) |
| 16 | +3. [Spatie](https://github.com/spatie) |
| 17 | + |
| 18 | + - Image Optimizer |
| 19 | + - Laravel Activitylog |
| 20 | + - Laravel Analytics |
| 21 | + - Laravel Collection Macros |
| 22 | + - Laravel Google Calendar |
| 23 | + - Laravel Html |
| 24 | + - Laravel Medialibrary |
| 25 | + - Laravel Menu |
| 26 | + - Laravel Permission |
| 27 | + - Laravel Referer |
| 28 | + - Laravel Responsecache |
| 29 | + - Laravel Sluggable |
| 30 | + |
| 31 | +4. [Hashids](https://github.com/ivanakimov/hashids.php) |
| 32 | +5. [Sweet Alert](https://github.com/uxweb/sweet-alert) |
| 33 | +6. [Sempro PHPUnit Pretty Printer](https://github.com/Sempro/phpunit-pretty-print) |
| 34 | + |
| 35 | +## Installation |
6 | 36 |
|
7 | 37 | ``` |
8 | | -$ composer create-project osinitiative/web-app-boilerplate your-project-name "1.0.1" |
| 38 | +$ composer create-project cleaniquecoders/laravel-boilerplate |
9 | 39 | ``` |
10 | 40 |
|
11 | | -# Packages |
12 | | - |
13 | | -Most of the packages from Spatie. |
| 41 | +Configure your `.env`, then: |
14 | 42 |
|
15 | | -1. Laravel Permission |
16 | | -2. Laravel Media Library |
17 | | -3. Laravel Activity |
18 | | -4. Laravel Newsletter |
19 | | -5. Laravel Analytics |
20 | | -6. Laravel Response Cache |
21 | | -7. Laravel Sluggable |
22 | | -8. Laravel Menu |
23 | | -9. Laravel Collection Macros |
24 | | -10. Laravel Google Calendar |
25 | | -11. Laravel Html |
26 | | -12. Image Optimizer |
| 43 | +``` |
| 44 | +$ php artisan reload:db |
| 45 | +``` |
27 | 46 |
|
28 | | -# Google API |
| 47 | +### Google API |
29 | 48 |
|
30 | 49 | Create [Google Service Account Credentials](https://console.developers.google.com/apis/dashboard?project=karnival-usahawan-desa) for: |
31 | 50 |
|
32 | 51 | 1. [Google Calendar](https://github.com/spatie/laravel-google-calendar#how-to-obtain-the-credentials-to-communicate-with-google-calendar) |
33 | 52 | 2. [Google Analytic](https://github.com/spatie/laravel-analytics#how-to-obtain-the-credentials-to-communicate-with-google-analytics) |
34 | 53 |
|
35 | | -# TODO |
| 54 | +## Usage |
| 55 | + |
| 56 | +### Commands |
| 57 | + |
| 58 | +There's some commands area ready built-in. Others, may refer to respective packages. |
| 59 | + |
| 60 | +- `reload:db` - Run `migrate:fresh --seed` with `profile:seed`. You may extend the usage. |
| 61 | +- `reload:cache` - Recache everything |
| 62 | + |
| 63 | +### Helpers |
| 64 | + |
| 65 | +**generate_sequence($count)** |
| 66 | + |
| 67 | +Generate sequence with leading zero like `000001`, `000002` and so on. |
| 68 | + |
| 69 | +Length for the leading zero can be configure in `.env` file - `DOCUMENT_SEQUENCE_LENGTH`. |
| 70 | + |
| 71 | +**abbrv($word, $unique_characters)** |
| 72 | + |
| 73 | +A helper to create abbreviation by removing non-alphanumeric, vowels. |
| 74 | + |
| 75 | +Passing second argument as false will return non-unique characters - means that you will see repeatative characters. |
| 76 | + |
| 77 | +Following are the sample usage and output: |
| 78 | + |
| 79 | +``` |
| 80 | +>>> abbrv("Cleanique Coders") |
| 81 | +=> "CLNQDRS" |
| 82 | +>>> abbrv("Cleanique Coders", false) |
| 83 | +=> "CLNQCDRS" |
| 84 | +``` |
| 85 | + |
| 86 | +**generate_reference($prefix, $count)** |
| 87 | + |
| 88 | +Generate document reference string. Usually a document have their own reference on the particular date event. |
| 89 | + |
| 90 | +For instance a payslip document have a reference number / string like `CCR/PYSL/2018/01/000001`. |
| 91 | + |
| 92 | +The format generate is `abbrv/Year/Month/Date/reference_id`. |
| 93 | + |
| 94 | +You can use in two ways: |
| 95 | + |
| 96 | +``` |
| 97 | +>>> generate_reference("Cleanique Coders Payroll") |
| 98 | +=> "CLNQ/CDRS/PYRL/2018/02/04/TBIPOU" |
| 99 | +>>> generate_reference("Cleanique Coders Payroll", 10) |
| 100 | +=> "CLNQ/CDRS/PYRL/2018/02/04/000010" |
| 101 | +``` |
| 102 | + |
| 103 | +The length of the `TBIPOU` or `000010` is depends on `DOCUMENT_SEQUENCE_LENGTH` in `.env` file. |
| 104 | + |
| 105 | +**hashids($salt, $length, $alphabet)** |
| 106 | + |
| 107 | +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). |
| 108 | + |
| 109 | +Following are an example how to use the helper. |
| 110 | + |
| 111 | +``` |
| 112 | +>>> hashids()->encode(1) |
| 113 | +=> "yR5ajG4DBwlz" |
| 114 | +>>> hashids('random-salt')->encode(1) |
| 115 | +=> "WZvoOMBr19YN" |
| 116 | +>>> hashids('random-salt', 24)->encode(1) |
| 117 | +=> "GPz1W4mLavAeqAwB2XZbOgQn" |
| 118 | +>>> hashids('random-salt', 6)->encode(1) |
| 119 | +=> "5qy0lP" |
| 120 | +>>> hashids('random-salt', 6, 'qwertyuiopasdfghjkl')->encode(1) |
| 121 | +=> "orgpqe" |
| 122 | +>>> hashids('random-salt', 6, ',./;<>?:"{}|[]\-=`~!@#$%^&*()')->encode(1) |
| 123 | +=> "{&(^&-" |
| 124 | +>>> hashids('random-salt', 12, ',./;<>?:"{}|[]\-=`~!@#$%^&*()')->encode(1) |
| 125 | +=> "~-!\`-&(*[{)" |
| 126 | +``` |
| 127 | + |
| 128 | +For `$salt`, by default it will use `APP_KEY`, but you may override it by passing the salt name at the first argument. |
| 129 | + |
| 130 | +For `$length`, you can pass any length of hashids you want to create. By default it's 12 characters. |
| 131 | + |
| 132 | +For `$alphabet`, you can put any characters as per example above. But remember, the alphabets need to be minimum of **16 characters**. |
| 133 | + |
| 134 | +**str_slug_fqcn($object)** |
| 135 | + |
| 136 | +Return slug name for given object. |
| 137 | + |
| 138 | +``` |
| 139 | +>>> $user = \App\Models\User::first(); |
| 140 | +=> App\Models\User {#1013 |
| 141 | + id: 1, |
| 142 | + hashslug: "krOErpkv6EVR", |
| 143 | + slug: "elza-bins", |
| 144 | + name: "Elza Bins", |
| 145 | + |
| 146 | + deleted_at: null, |
| 147 | + created_at: "2018-02-04 03:11:07", |
| 148 | + updated_at: "2018-02-04 03:11:07", |
| 149 | + } |
| 150 | +>>> str_slug_fqcn($user) |
| 151 | +=> "app-models-user" |
| 152 | +``` |
| 153 | + |
| 154 | +**audit($model, $message, $causedBy)** |
| 155 | + |
| 156 | +Simply record audit trail on given `$model`, with proper `$message`. You can optionally passed the third argument - `$causedBy`. |
| 157 | + |
| 158 | +``` |
| 159 | +>>> auth()->loginUsingId(1) |
| 160 | +>>> $user = \App\Models\User::first(); |
| 161 | +>>> audit($user, 'access via terminal') |
| 162 | +>>> auth()->user()->activity->toArray() |
| 163 | +=> [ |
| 164 | + [ |
| 165 | + "id" => 4, |
| 166 | + "log_name" => "default", |
| 167 | + "description" => "User successfully logged in.", |
| 168 | + "subject_id" => 1, |
| 169 | + "subject_type" => "App\Models\User", |
| 170 | + "causer_id" => 1, |
| 171 | + "causer_type" => "App\Models\User", |
| 172 | + "properties" => Illuminate\Support\Collection {#971 |
| 173 | + all: [], |
| 174 | + }, |
| 175 | + "created_at" => "2018-02-04 03:18:50", |
| 176 | + "updated_at" => "2018-02-04 03:18:50", |
| 177 | + ], |
| 178 | + [ |
| 179 | + "id" => 5, |
| 180 | + "log_name" => "default", |
| 181 | + "description" => "access via terminal", |
| 182 | + "subject_id" => 1, |
| 183 | + "subject_type" => "App\Models\User", |
| 184 | + "causer_id" => 1, |
| 185 | + "causer_type" => "App\Models\User", |
| 186 | + "properties" => Illuminate\Support\Collection {#980 |
| 187 | + all: [], |
| 188 | + }, |
| 189 | + "created_at" => "2018-02-04 03:19:16", |
| 190 | + "updated_at" => "2018-02-04 03:19:16", |
| 191 | + ], |
| 192 | + ] |
| 193 | +``` |
| 194 | + |
| 195 | +## Test |
| 196 | + |
| 197 | +To run the test, type `vendor/bin/phpunit` in your terminal. |
| 198 | + |
| 199 | +To have codes coverage, please ensure to install PHP XDebug then run the following command: |
| 200 | + |
| 201 | +``` |
| 202 | +$ vendor/bin/phpunit -v --coverage-text --colors=never --stderr |
| 203 | +``` |
| 204 | + |
| 205 | +## Contributions |
| 206 | + |
| 207 | +Everyone are welcome to contribute to this package. However, it's a good practice to provide: |
| 208 | + |
| 209 | +1. The problem you solved |
| 210 | +2. Provide test |
| 211 | +3. Documentation |
| 212 | + |
| 213 | +Without these 3, you may add extra work for the maintainer. |
| 214 | + |
| 215 | +## License |
36 | 216 |
|
37 | | -1. Media Library for User |
| 217 | +This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). |
0 commit comments