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