

Sail artisan make:factory CategoryFactory -model=Category # Create a factory class for category model Sail artisan make:factory QuestFactory -model=Quest Run the following commands: # Create a factory class for quest model We need data to work with, but as developers we are too lazy to manually do it.įirst, we'll create the factory classes for both the quest and category model. Our database should be updated! Next we should put some data into our tables. With both the migrations and models ready, we can apply the changes to the database.

$table->foreignId('category_id')->constrained() Īs you can see, we declared the category_id to be a foreignId. This will create a model named Quest and a migration file for it. Run the command to make a model and migration file for quest: sail artisan make:model -m Quest You will have some errors concerning the Quest model, but no worries – we will handle that next.

ELOQUENT EXAMPLE INSTALL
Moving on, if you go to localhost you should see something like this: Default Laravel Home Pageīut before we move on, there are some packages that we need to install first: # IDE helper for laravel, always useful to have.
ELOQUENT EXAMPLE CODE
You can do that by adding this piece of code to your bashrc or zshrc: # in ~./zshrc or ~./bashrc Let's then run the containers using sail: # Run the containersĪt this point I suggest you alias sail to. If all goes well, you should now see a docker-compose.yml file in your project directory. It's gonna ask you which services to install. Next let's setup sail like this: # Move into the project This will create a new project in a new directory called quest_journal.
ELOQUENT EXAMPLE HOW TO
How to Initialize the ProjectĬreate a Laravel project using this command: composer create-project laravel/laravel quest_journal Database Schemaīy the end of this post we will create a CRUD GraphQL API for each model. The project will consist of only two models called Quests and Categories.
ELOQUENT EXAMPLE SERIES
I like RPG games like the Elder Scrolls Series or Final Fantasy, so of course our app will be about games. Knowledge of PHP (Syntax, OOP, and so on).Basic knowledge of Laravel (Eloquent, Migrations, MVC, Routes, and so on).

Docker-Compose 1.29.1 (Any other version should be fine).Docker 20.10.6 (Any other version should be fine).Prerequisitesīefore we begin, make sure to have these installed on your system: You can find the final project on GitHub here. It was actually easier than I thought, so I would like to share with you what I've learned about GraphQL by creating a simple demo project together. Words like Docker, Kubernetes, and GraphQL seemed quite scary.īut I mustered up the courage and started to learn them all one by one. And I was very intimidated by all the technology I didn't yet know. Two years ago, I started working professionally as a backend developer. In this article, I'll walk you through how to set up your own GraphQL API using PHP and Laravel.
