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

50 行
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Father;
use App\Models\FatherRelation;
class FathersController extends Controller {
public function list () {
$result = [];
$father_select = ['id', 'company', 'image'];
$father_relation_select = ['created_at'];
// 親一覧の取得に成功
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];
}
// 親一覧の取得に失敗
return ['status_code' => 400];
}
}