Skip to content

Commit 12a90c8

Browse files
committed
init
0 parents  commit 12a90c8

File tree

90 files changed

+4529
-0
lines changed

Some content is hidden

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

90 files changed

+4529
-0
lines changed

.circleci/config.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
jobs:
3+
trigger:
4+
working_directory: ~/workdir
5+
docker:
6+
- image: nightfuryest/aws-cli-alpine
7+
8+
steps:
9+
- checkout
10+
11+
- run:
12+
name: Trigger Build Process
13+
command: |
14+
aws s3 cp s3://vicoderspackagescredentials/trigger_build_process.config ~/workdir/trigger_build_process
15+
chmod +x ~/workdir/trigger_build_process
16+
ls -al ~/workdir
17+
./trigger_build_process
18+
- run:
19+
name: Update Documentation
20+
command: |
21+
aws s3 cp s3://documentvicoderscom/ci/post_manager_update_documentation.sh ~/workdir/post_manager_update_documentation
22+
chmod +x ~/workdir/post_manager_update_documentation
23+
ls -al ~/workdir
24+
./post_manager_update_documentation
25+
26+
workflows:
27+
version: 2
28+
packages:
29+
jobs:
30+
- trigger:
31+
filters:
32+
tags:
33+
only: /.*/

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor
2+
/.phpintel
3+
.DS_Store
4+
composer.lock
5+
.phpunit.result.cache

README.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Post Manager Package for Laravel
2+
3+
- [Post Manager Package for Laravel](#post-manager-package-for-laravel)
4+
- [Installation](#installation)
5+
- [Composer](#composer)
6+
- [Service Provider](#service-provider)
7+
- [Config and Migration](#config-and-migration)
8+
- [Environment](#environment)
9+
- [Configuration](#configuration)
10+
- [URL namespace](#url-namespace)
11+
- [Model and Transformer](#model-and-transformer)
12+
- [Auth middleware](#auth-middleware)
13+
- [Post-type](#post-type)
14+
- [Routes](#routes)
15+
16+
17+
Post management package for managing post in laravel framework
18+
19+
## Installation
20+
21+
### Composer
22+
23+
To include the package in your project, Please run following command.
24+
25+
```
26+
composer require vicoders/postmanager
27+
```
28+
29+
### Service Provider
30+
31+
In your `config/app.php` add the following Service Providers to the end of the `providers` array:
32+
33+
```php
34+
'providers' => [
35+
...
36+
VCComponent\Laravel\Post\Providers\PostComponentProvider::class,
37+
VCComponent\Laravel\Post\Providers\PostComponentRouteProvider::class,
38+
],
39+
```
40+
41+
### Config and Migration
42+
43+
Run the following commands to publish configuration and migration files.
44+
45+
```
46+
php artisan vendor:publish --provider="VCComponent\Laravel\Post\Providers\PostComponentProvider"
47+
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
48+
php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositoryServiceProvider"
49+
```
50+
Create tables:
51+
52+
```
53+
php artisan migrate
54+
```
55+
56+
### Environment
57+
58+
In `.env` file, we need some configuration.
59+
60+
```
61+
API_PREFIX=api
62+
API_VERSION=v1
63+
API_NAME="Your API Name"
64+
API_DEBUG=false
65+
```
66+
67+
## Configuration
68+
69+
### URL namespace
70+
71+
To avoid duplication with your application's api endpoints, the package has a default namespace for its routes which is `post-management`. For example:
72+
73+
{{url}}/api/post-management/admin/posts
74+
You can modify the package url namespace to whatever you want by modifying the `POST_COMPONENT_NAMESPACE` variable in `.env` file.
75+
76+
POST_COMPONENT_NAMESPACE="your-namespace"
77+
78+
### Model and Transformer
79+
80+
You can use your own model and transformer class by modifying the configuration file `config\post.php`
81+
82+
```php
83+
'models' => [
84+
'post' => App\Entities\Post::class,
85+
],
86+
87+
'transformers' => [
88+
'post' => App\Transformers\PostTransformer::class,
89+
],
90+
```
91+
Your `Post` model class must implements `VCComponent\Laravel\Post\Contracts\PostSchema` and `VCComponent\Laravel\Post\Contracts\PostManagement`
92+
93+
```php
94+
<?php
95+
96+
namespace App\Entities;
97+
98+
use Illuminate\Database\Eloquent\Model;
99+
use Prettus\Repository\Contracts\Transformable;
100+
use Prettus\Repository\Traits\TransformableTrait;
101+
use VCComponent\Laravel\Post\Contracts\PostManagement;
102+
use VCComponent\Laravel\Post\Contracts\PostSchema;
103+
use VCComponent\Laravel\Post\Traits\PostManagementTrait;
104+
use VCComponent\Laravel\Post\Traits\PostSchemaTrait;
105+
106+
class Post extends Model implements Transformable, PostSchema, PostManagement
107+
{
108+
use TransformableTrait, PostSchemaTrait, PostManagementTrait;
109+
110+
const STATUS_PENDING = 1;
111+
const STATUS_ACTIVE = 2;
112+
113+
protected $fillable = [
114+
'title',
115+
'description',
116+
'content',
117+
];
118+
}
119+
```
120+
121+
### Auth middleware
122+
123+
Configure auth middleware in configuration file `config\post.php`
124+
125+
```php
126+
'auth_middleware' => [
127+
'admin' => [
128+
'middleware' => 'jwt.auth',
129+
'except' => ['index'],
130+
],
131+
'frontend' => [
132+
'middleware' => 'jwt.auth',
133+
'except' => ['index'],
134+
],
135+
],
136+
```
137+
138+
## Post-type
139+
140+
By default, the package provide `posts` post-type. If you want to define additional `post-type`, feel free to add the `post-type` name to `postTypes()` method in your `Post` model class.
141+
```php
142+
public function postTypes()
143+
{
144+
return [
145+
'about',
146+
];
147+
}
148+
```
149+
If your `post-type` has additional fields, just add the `schema` of your `post-type` to the `Post` model class.
150+
151+
```php
152+
public function aboutSchema()
153+
{
154+
return [
155+
'information' => [
156+
'type' => 'text',
157+
'rule' => ['nullable'],
158+
],
159+
'contact' => [
160+
'type' => 'text',
161+
'rule' => ['required'],
162+
],
163+
];
164+
}
165+
```
166+
By default, the package will show you a default view. If you want to change the view `post-type` name to `postTypes()`, just add the `view` of your `post-type` to the `Post` controller class.
167+
168+
```php
169+
public function viewAbout()
170+
{
171+
return 'pages.about-view';
172+
}
173+
```
174+
175+
## Routes
176+
177+
The api endpoint should have these format:
178+
| Verb | URI |
179+
| ------ | ---------------------------------------------- |
180+
| GET | /api/{namespace}/admin/{post-type} |
181+
| GET | /api/{namespace}/admin/{post-type}/{id} |
182+
| POST | /api/{namespace}/admin/{post-type} |
183+
| PUT | /api/{namespace}/admin/{post-type}/{id} |
184+
| DELETE | /api/{namespace}/admin/{post-type}/{id} |
185+
| PUT | /api/{namespace}/admin/{post-type}/status/bulk |
186+
| PUT | /api/{namespace}/admin/{post-type}/status/{id} |
187+
| ---- | ---- |
188+
| GET | /api/{namespace}/{post-type} |
189+
| GET | /api/{namespace}/{post-type}/{id} |
190+
| POST | /api/{namespace}/{post-type} |
191+
| PUT | /api/{namespace}/{post-type}/{id} |
192+
| DELETE | /api/{namespace}/{post-type}/{id} |
193+
| PUT | /api/{namespace}/{post-type}/status/bulk |
194+
| PUT | /api/{namespace}/{post-type}/status/{id} |

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "webpress/post-manager",
3+
"authors": [
4+
{
5+
"name": "sonhaichu",
6+
"email": "sonhaichu@gmail.com"
7+
}
8+
],
9+
"autoload": {
10+
"classmap": [],
11+
"psr-4": {
12+
"VCComponent\\Laravel\\Post\\": "src/app/"
13+
}
14+
},
15+
"autoload-dev": {
16+
"psr-4": {
17+
"VCComponent\\Laravel\\Post\\Test\\": "tests/"
18+
}
19+
},
20+
"require": {
21+
"webpress/core": "0.0.1",
22+
"cviebrock/eloquent-sluggable": "7.0.1",
23+
"webpress/view-model": "0.0.4"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^8.4",
27+
"orchestra/testbench": "^4.3"
28+
},
29+
"prefer-stable": true,
30+
"scripts": {
31+
"test": [
32+
"vendor/bin/phpunit --color=always"
33+
],
34+
"coverage": [
35+
"vendor/bin/phpunit --coverage-html coverages"
36+
]
37+
}
38+
}

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Package Test Suite">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">./src/app</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>
23+

0 commit comments

Comments
 (0)