|
|
@ -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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|