Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit b794415

Browse files
committed
Merge branch 'feature/restructure' into develop
2 parents b78edcd + 699b1f8 commit b794415

File tree

80 files changed

+731
-1052
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+731
-1052
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: php
2+
3+
php:
4+
- 7.0
5+
- 7.1
6+
- 7.2
7+
8+
before_script:
9+
- travis_retry composer self-update
10+
- travis_retry composer update --prefer-source --no-interaction --dev
11+
12+
script:
13+
- vendor/bin/phpunit -v --coverage-text --colors=never --stderr

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) <Nasrul Hazim>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 202 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,217 @@
1-
# Web Application Boilerplate
1+
[![Build Status](https://travis-ci.org/cleaniquecoders/laravel-boilerplate.svg?branch=master)](https://travis-ci.org/cleaniquecoders/laravel-boilerplate) [![Latest Stable Version](https://poser.pugx.org/cleaniquecoders/laravel-boilerplate/v/stable)](https://packagist.org/packages/cleaniquecoders/laravel-boilerplate) [![Total Downloads](https://poser.pugx.org/cleaniquecoders/laravel-boilerplate/downloads)](https://packagist.org/packages/cleaniquecoders/laravel-boilerplate) [![License](https://poser.pugx.org/cleaniquecoders/laravel-boilerplate/license)](https://packagist.org/packages/cleaniquecoders/laravel-boilerplate)
22

3-
A boilerplate to speed up development.
3+
# Laravel Boilerplate
44

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
636

737
```
8-
$ composer create-project osinitiative/web-app-boilerplate your-project-name "1.0.1"
38+
$ composer create-project cleaniquecoders/laravel-boilerplate
939
```
1040

11-
# Packages
12-
13-
Most of the packages from Spatie.
41+
Configure your `.env`, then:
1442

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+
```
2746

28-
# Google API
47+
### Google API
2948

3049
Create [Google Service Account Credentials](https://console.developers.google.com/apis/dashboard?project=karnival-usahawan-desa) for:
3150

3251
1. [Google Calendar](https://github.com/spatie/laravel-google-calendar#how-to-obtain-the-credentials-to-communicate-with-google-calendar)
3352
2. [Google Analytic](https://github.com/spatie/laravel-analytics#how-to-obtain-the-credentials-to-communicate-with-google-analytics)
3453

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
36216

37-
1. Media Library for User
217+
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class ReloadCacheCommand extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'reload:cache';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Reload all caches';
22+
23+
/**
24+
* Create a new command instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct()
29+
{
30+
parent::__construct();
31+
}
32+
33+
/**
34+
* Execute the console command.
35+
*
36+
* @return mixed
37+
*/
38+
public function handle()
39+
{
40+
$this->call('cache:clear');
41+
$this->call('config:cache');
42+
$this->call('responsecache:flush');
43+
$this->call('route:cache');
44+
$this->call('view:clear');
45+
}
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class ReloadDbCommand extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'reload:db';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Reload Database';
22+
23+
/**
24+
* Create a new command instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct()
29+
{
30+
parent::__construct();
31+
}
32+
33+
/**
34+
* Execute the console command.
35+
*
36+
* @return mixed
37+
*/
38+
public function handle()
39+
{
40+
$this->call('migrate:fresh', ['--seed' => true]);
41+
$this->info('Seeding Profile Dependencies');
42+
$this->call('profile:seed');
43+
}
44+
}

app/Console/Kernel.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OSI\Console;
3+
namespace App\Console;
44

55
use Illuminate\Console\Scheduling\Schedule;
66
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -13,7 +13,8 @@ class Kernel extends ConsoleKernel
1313
* @var array
1414
*/
1515
protected $commands = [
16-
//
16+
\App\Console\Commands\ReloadDbCommand::class,
17+
\App\Console\Commands\ReloadCacheCommand::class,
1718
];
1819

1920
/**
@@ -35,7 +36,7 @@ protected function schedule(Schedule $schedule)
3536
*/
3637
protected function commands()
3738
{
38-
$this->load(__DIR__.'/Commands');
39+
$this->load(__DIR__ . '/Commands');
3940

4041
require base_path('routes/console.php');
4142
}

0 commit comments

Comments
 (0)