2021-09-30 13:26:29 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2021-10-01 12:44:45 +09:00
|
|
|
use App\Models\FatherRelation;
|
|
|
|
|
2021-09-30 13:26:29 +09:00
|
|
|
class FatherRelationsController extends Controller {
|
2021-10-01 14:18:52 +09:00
|
|
|
public function register (Request $r) {
|
|
|
|
if (!isset($r->child_id) || !isset($r->father_id) || !isset($r->hire_at)) {
|
|
|
|
return ['status_code' => 400, 'success_messages' => '子の登録に失敗しました。'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$insert = [
|
|
|
|
'father_id' => $r->father_id,
|
|
|
|
'child_id' => $r->child_id,
|
|
|
|
'hire_at' => date('Y-m-d H:i:s', strtotime($r->hire_at))
|
|
|
|
];
|
|
|
|
|
|
|
|
if (FatherRelation::create($insert)) {
|
|
|
|
return ['status_code' => 200, 'success_messages' => '子の登録に成功しました。'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['status_code' => 400, 'success_messages' => '子の登録に失敗しました。'];
|
2021-10-01 12:44:45 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
public function updateHireDate (Request $r, $child_id) {
|
|
|
|
if (!isset($child_id) || !isset($r->father_id) || !isset($r->hire_at)) {
|
|
|
|
return ['status_code' => 400, 'success_messages' => '子の入社日の更新に失敗しました。'];
|
|
|
|
}
|
2021-10-01 12:44:45 +09:00
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
$update = ['hire_at' => date('Y-m-d H:i:s', strtotime($r->hire_at))];
|
2021-10-01 12:44:45 +09:00
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
if (FatherRelation::where('father_id', $r->father_id)->where('child_id', $child_id)->update($update)) {
|
|
|
|
return ['status_code' => 200, 'success_messages' => '子の入社日の更新に成功しました。'];
|
|
|
|
}
|
2021-09-30 13:26:29 +09:00
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
return ['status_code' => 400, 'success_messages' => '子の入社日の更新に失敗しました。'];
|
2021-10-01 12:44:45 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
public function deleteRelationFather ($father_id) {
|
|
|
|
// 削除成功
|
|
|
|
if (FatherRelation::where('father_id', $father_id)->delete()) {
|
|
|
|
return ['status_code' => 200];
|
|
|
|
}
|
2021-10-01 12:44:45 +09:00
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
// 削除失敗
|
|
|
|
return ['status_code' => 400];
|
2021-10-01 12:44:45 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
public function deleteRelationChild ($child_id) {
|
|
|
|
// 削除成功
|
|
|
|
if (FatherRelation::where('child_id', $child_id)->delete()) {
|
|
|
|
return ['status_code' => 200];
|
|
|
|
}
|
2021-09-30 13:26:29 +09:00
|
|
|
|
2021-10-01 14:18:52 +09:00
|
|
|
// 削除失敗
|
|
|
|
return ['status_code' => 400];
|
2021-09-30 13:26:29 +09:00
|
|
|
}
|
|
|
|
}
|