-
Notifications
You must be signed in to change notification settings - Fork 56
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
26 changed files
with
786 additions
and
1 deletion.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
app/Http/Controllers/Api/Master/PersonCategoryController.php
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,84 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Master; | ||
|
||
use App\Http\Controllers\Api\ApiController; | ||
use App\Http\Requests\Master\PersonCategory\StorePersonCategoryRequest; | ||
use App\Http\Requests\Master\PersonCategory\UpdatePersonCategoryRequest; | ||
use App\Http\Resources\Master\PersonCategory\PersonCategoryCollection; | ||
use App\Http\Resources\Master\PersonCategory\PersonCategoryResource; | ||
use App\Model\Master\PersonCategory; | ||
use Illuminate\Http\Request; | ||
|
||
class PersonCategoryController extends ApiController | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$limit = $request->input('limit') ?? 0; | ||
|
||
return new PersonCategoryCollection(PersonCategory::paginate($limit)); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(StorePersonCategoryRequest $request) | ||
{ | ||
$personCategory = new PersonCategory; | ||
$personCategory->code = $request->input('code'); | ||
$personCategory->name = $request->input('name'); | ||
$personCategory->save(); | ||
|
||
return new PersonCategoryResource($personCategory); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($id) | ||
{ | ||
return new PersonCategoryResource(PersonCategory::find($id)); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(UpdatePersonCategoryRequest $request, $id) | ||
{ | ||
$personCategory = PersonCategory::find($id); | ||
$personCategory->code = $request->input('code'); | ||
$personCategory->name = $request->input('name'); | ||
$personCategory->save(); | ||
|
||
return new PersonCategoryResource($personCategory); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
PersonCategory::find($id)->delete(); | ||
|
||
return response(null, 204); | ||
} | ||
|
||
} |
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,93 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Master; | ||
|
||
use App\Http\Controllers\Api\ApiController; | ||
use App\Http\Requests\Master\Person\StorePersonRequest; | ||
use App\Http\Requests\Master\Person\UpdatePersonRequest; | ||
use App\Http\Resources\Master\Person\PersonResource; | ||
use App\Model\Master\Person; | ||
use Illuminate\Http\Request; | ||
|
||
class PersonController extends ApiController | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$limit = $request->input('limit') ?? 0; | ||
|
||
return new PersonCollection(Person::paginate($limit)); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(StorePersonRequest $request) | ||
{ | ||
$person = new Person; | ||
$person->code = $request->input('code'); | ||
$person->name = $request->input('name'); | ||
$person->email = $request->input('email'); | ||
$person->phone = $request->input('phone'); | ||
$person->address = $request->input('address'); | ||
$person->notes = $request->input('notes'); | ||
$person->person_categories_id = $request->input('person_categories_id'); | ||
$person->person_groups_id = $request->input('person_groups_id'); | ||
$person->save(); | ||
|
||
return new PersonResource($person); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($id) | ||
{ | ||
return new PersonResource(Person::find($id)); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(UpdatePersonRequest $request, $id) | ||
{ | ||
$person = Person::find($id); | ||
$person->code = $request->input('code'); | ||
$person->name = $request->input('name'); | ||
$person->phone = $request->input('phone'); | ||
$person->address = $request->input('address'); | ||
$person->notes = $request->input('notes'); | ||
$person->person_categories_id = $request->input('person_categories_id'); | ||
$person->person_groups_id = $request->input('person_groups_id'); | ||
$person->save(); | ||
|
||
return new PersonResource($person); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
Person::find($id)->delete(); | ||
|
||
return response(null, 204); | ||
} | ||
} |
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,83 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Master; | ||
|
||
use App\Http\Controllers\Api\ApiController; | ||
use App\Http\Requests\Master\PersonGroup\StorePersonGroupRequest; | ||
use App\Http\Requests\Master\PersonGroup\UpdatePersonGroupRequest; | ||
use App\Http\Resources\Master\PersonGroup\PersonGroupCollection; | ||
use App\Http\Resources\Master\PersonGroup\PersonGroupResource; | ||
use App\Model\Master\PersonGroup; | ||
use Illuminate\Http\Request; | ||
|
||
class PersonGroupController extends ApiController | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$limit = $request->input('limit') ?? 0; | ||
|
||
return new PersonGroupCollection(PersonGroup::paginate($limit)); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(StorePersonGroupRequest $request) | ||
{ | ||
$personGroup = new PersonGroup; | ||
$personGroup->code = $request->input('code'); | ||
$personGroup->name = $request->input('name'); | ||
$personGroup->save(); | ||
|
||
return new PersonGroupResource($personGroup); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($id) | ||
{ | ||
return new PersonGroupResource(PersonGroup::find($id)); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(UpdatePersonGroupRequest $request, $id) | ||
{ | ||
$personGroup = PersonGroup::find($id); | ||
$personGroup->code = $request->input('code'); | ||
$personGroup->name = $request->input('name'); | ||
$personGroup->save(); | ||
|
||
return new PersonGroupResource($personGroup); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
PersonGroup::find($id)->delete(); | ||
|
||
return response(null, 204); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Master\Person; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Http\Request; | ||
|
||
class StorePersonRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(Request $request) | ||
{ | ||
return [ | ||
'name' => [ | ||
'required', | ||
'unique:persons,name,NULL,id' | ||
. ',person_categories_id,' . $request->get('person_categories_id') | ||
], | ||
'code' => 'unique:persons,code', | ||
'person_categories_id' => 'required' | ||
]; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Master\Person; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class UpdatePersonRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/Http/Requests/Master/PersonCategory/StorePersonCategoryRequest.php
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,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Master\PersonCategory; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StorePersonCategoryRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'code' => 'required|unique:person_categories,code', | ||
'name' => 'required|unique:person_categories,name', | ||
]; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/Http/Requests/Master/PersonCategory/UpdatePersonCategoryRequest.php
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,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Master\PersonCategory; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class UpdatePersonCategoryRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'code' => 'required|unique:person_categories,code,' . $this->id, | ||
'name' => 'required|unique:person_categories,name,' . $this->id, | ||
]; | ||
} | ||
} |
Oops, something went wrong.