Browse Source

company mangement

pull/3/head
farhan048 1 year ago
parent
commit
79e044fbd5
  1. 137
      app/Http/Controllers/CompanyController.php
  2. 2
      app/Models/Company.php
  3. 8
      routes/web.php

137
app/Http/Controllers/CompanyController.php

@ -7,79 +7,104 @@ use Illuminate\Http\Request;
class CompanyController extends Controller class CompanyController extends Controller
{ {
/** public function add(Request $request)
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{ {
// $this->validate($request, [
'name' => 'required',
'description' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Company::create($data);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400);
}
} }
/** public function edit($id)
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{ {
// if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
} }
/** $result = Company::find($id);
* Store a newly created resource in storage.
* if ($result) {
* @param \Illuminate\Http\Request $request return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
* @return \Illuminate\Http\Response } else {
*/ return response()->json(['status' => 'failed', 'message' => 'failed get data Company, please try again later!', 'code' => 400], 400);
public function store(Request $request) }
{
//
} }
/** public function update(Request $request, $id)
* Display the specified resource.
*
* @param \App\Company $company
* @return \Illuminate\Http\Response
*/
public function show(Company $company)
{ {
// if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$data = Company::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
} }
/**
* Show the form for editing the specified resource. if ($result) {
* return response()->json(['status' => 'success', 'message' => 'data Company successfully updated!', 'code' => 200], 200);
* @param \App\Company $company } else {
* @return \Illuminate\Http\Response return response()->json(['status' => 'failed', 'message' => 'data Company failed updated!', 'code' => 400], 400);
*/ }
public function edit(Company $company) }
public function delete($id)
{ {
// $data = Company::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
} }
/**
* Update the specified resource in storage. if ($delete) {
* return response()->json(['status' => 'success', 'message' => 'data Company successfully deleted!', 'code' => 200], 200);
* @param \Illuminate\Http\Request $request } else {
* @param \App\Company $company return response()->json(['status' => 'failed', 'message' => 'data Company failed deleted!', 'code' => 400], 400);
* @return \Illuminate\Http\Response }
*/ }
public function update(Request $request, Company $company)
public function search(Request $request)
{ {
// $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_company');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
/** public function list()
* Remove the specified resource from storage.
*
* @param \App\Company $company
* @return \Illuminate\Http\Response
*/
public function destroy(Company $company)
{ {
// $data = Company::all();
$countData = $data->count();
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get list Company, please try again later!', 'code' => 400], 400);
}
} }
} }

2
app/Models/Company.php

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Company extends Model class Company extends Model
{ {
protected $table = 'm_divisi'; protected $table = 'm_company';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';

8
routes/web.php

@ -496,6 +496,12 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/broadcast/search', 'BroadcastController@search'); $router->post('/broadcast/search', 'BroadcastController@search');
$router->delete('/broadcast/delete/{id}', 'BroadcastController@delete'); $router->delete('/broadcast/delete/{id}', 'BroadcastController@delete');
$router->get('/broadcast/list', 'BroadcastController@list'); $router->get('/broadcast/list', 'BroadcastController@list');
});
$router->post('/company-management/add', 'CompanyController@add');
$router->get('/company-management/edit/{id}', 'CompanyController@edit');
$router->put('/company-management/update/{id}', 'CompanyController@update');
$router->post('/company-management/search', 'CompanyController@search');
$router->delete('/company-management/delete/{id}', 'CompanyController@delete');
$router->get('/company-management/list', 'CompanyController@list');
});
}); });

Loading…
Cancel
Save