API設計4番号

このコミットが含まれているのは:
守矢諏訪子 2021-09-28 14:38:41 +09:00
コミット e2340b45b3
21個のファイルの変更585行の追加278行の削除

ファイルの表示

@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class FathersController {
public $error = [];
public function list () {
// 親一覧の取得に成功
if ($list = DB::table('fathers')->orderBy('created_at', 'desc')->get()->toArray()) return ['status_code' => 200, 'params' => $list];
// 親一覧の取得に失敗
return ['status_code' => 400];
}
}

14
backend/app/Models/FatherRelations.php ノーマルファイル
ファイルの表示

@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class FatherRelations extends Model
{
public function father ()
{
return $this->belongsTo(Fathers::class);
}
}

14
backend/app/Models/Fathers.php ノーマルファイル
ファイルの表示

@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Fathers extends Model
{
public function relations ()
{
return $this->hasMany(FatherRelations::class);
}
}

646
backend/composer.lock generated

ファイル差分が大きすぎるため省略します 差分を読み込み

ファイルの表示

@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\FatherRelations;
use Illuminate\Database\Eloquent\Factories\Factory;
class FatherRelationsFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = FatherRelations::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}

28
backend/database/factories/FathersFactory.php ノーマルファイル
ファイルの表示

@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\Fathers;
use Illuminate\Database\Eloquent\Factories\Factory;
class FathersFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Fathers::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}

ファイルの表示

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFathersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('fathers', function (Blueprint $table) {
$table->id();
$table->integer('company');
$table->string('image');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('fathers');
}
}

ファイルの表示

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFatherRelationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('father_relations', function (Blueprint $table) {
$table->id();
$table->integer('father_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('father_relations');
}
}

ファイルの表示

@ -14,5 +14,7 @@ class DatabaseSeeder extends Seeder
public function run()
{
// \App\Models\User::factory(10)->create();
$this->call(FathersSeeder::class);
$this->call(FatherRelationsSeeder::class);
}
}

ファイルの表示

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class FatherRelationsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('father_relations')->insert([
'father_id' => 1,
]);
}
}

22
backend/database/seeders/FathersSeeder.php ノーマルファイル
ファイルの表示

@ -0,0 +1,22 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class FathersSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('fathers')->insert([
'company' => 1,
'image' => '',
]);
}
}

ファイルの表示

@ -17,3 +17,6 @@ use Illuminate\Support\Facades\Route;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
// FathersController
Route::get('/fathers/list/', '\App\Http\Controllers\Api\FathersController@list');

0
backend/storage/app/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/app/public/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/framework/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/framework/cache/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/framework/cache/data/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/framework/sessions/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/framework/testing/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/framework/views/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示

0
backend/storage/logs/.gitignore vendored ノーマルファイル → 実行可能ファイル
ファイルの表示