このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
kikikan/backend/app/Http/Controllers/Api/FathersController.php

72 行
1.9 KiB
PHP
Raw 通常表示 履歴

2021-09-28 14:38:41 +09:00
<?php
namespace App\Http\Controllers\Api;
2021-09-30 13:20:54 +09:00
use App\Http\Controllers\Controller;
2021-09-28 14:38:41 +09:00
use Illuminate\Http\Request;
2021-09-30 13:20:54 +09:00
use App\Models\Father;
use App\Models\FatherRelation;
2021-09-28 14:38:41 +09:00
2021-09-30 13:20:54 +09:00
class FathersController extends Controller {
2021-09-28 14:38:41 +09:00
public function list () {
2021-09-30 13:20:54 +09:00
$result = [];
$father_select = ['id', 'company', 'image'];
$father_relation_select = ['created_at'];
2021-09-28 14:38:41 +09:00
// 親一覧の取得に成功
2021-09-30 13:20:54 +09:00
if ($list = Father::select($father_select)->orderBy('created_at', 'desc')->get()->toArray()) {
foreach ($list as $i => $l) {
$result[] = $l;
$result[$i]['relation'] = FatherRelation::select($father_relation_select)->where('father_id', $l['id'])->first();
}
return ['status_code' => 200, 'params' => $result];
}
// 親一覧の取得に失敗
return ['status_code' => 400];
}
public function listOfChild (Request $r) {
$result = [];
$father_select = ['id', 'company', 'image'];
// 親一覧の取得に成功
if ($list = FatherRelation::where('child_id', $r->child_id)->orderBy('created_at', 'desc')->get()->toArray()) {
$result = [];
foreach ($list as $l) {
$result[] = Father::select($father_select)->find($l['father_id']);
}
return ['status_code' => 200, 'params' => $result];
}
2021-09-28 14:38:41 +09:00
// 親一覧の取得に失敗
return ['status_code' => 400];
}
public function detail ($father_id) {
$father_select = ['id', 'email', 'company', 'image', 'tel'];
// 親詳細の取得に成功
if ($result = Father::select($father_select)->where('id', $father_id)->orderBy('created_at', 'desc')->get()->toArray()) {
return ['status_code' => 200, 'params' => $result];
}
// 親詳細の取得に失敗
return ['status_code' => 400];
}
public function delete ($father_id) {
// 削除成功
if (Father::where('id', $father_id)->delete()) {
return ['status_code' => 200];
}
// 削除失敗
return ['status_code' => 400];
}
2021-09-28 14:38:41 +09:00
}