function up(): void { Schema::create('posts', function (Blueprint $table) { $table->id('id'); $table->string('title'); $table->string('content'); $table->timestamps(); }); } QPTUTςʔϒϧͷ.JHSBUJPOͷఆٛ final class Post extends Model { } 1PTUϞσϧͷఆٛ
w postࢦఆͨ͠idʹҰக͢ΔPostϞσϧΛฦ٫ type Post { id: ID! title: String! content: String! } type Query { posts: [Post!]! post(id: Int!): Post } graphql/schema.graphql
artisan lighthouse:query 操作名 use App\Models\Post as ModelsPost; // posts のリゾルバ final readonly class Posts { public function __invoke() { $posts = ModelsPost::all(); return $posts; } } App\GraphQL\Queries\Posts use App\Models\Post as ModelsPost; // post のリゾルバ final readonly class Post { public function __invoke(null $_, array $args) { $id = $args['id']; $post = ModelsPost::find($id); return $post; } } App\GraphQL\Queries\Post