Creating a Laravel application ~ part I of Laravel API Setup.

Creating a Laravel application ~ part I of Laravel API Setup.

Decided to start a Laravel development article series on setting up a new Laravel project - the way I personally do it. The articles will be beginner-friendly while focusing on the technical aspect of it. You can skip this first article if you're an experienced developer or you can skim through to understand the genesis of these articles series. Finally, if you want to get notified whenever I publish a new article then go ahead and subscribe. I assume you have a basic understanding of PHP and you've used Laravel before and you've set up your development environment.

Create a new Laravel project.

Let's get started with a new Laravel project, at the time of writing this article, Laravel is at version v8.21.*. The quickest way of getting started with Laravel is by using composer to create a Laravel project, you can replace the appName with your application name. Open your terminal and run

composer create-project laravel/laravel appName

in your development directory.
There are other ways of creating Laravel application. I often use Laravel installer to create my Laravel applications. First, you will have to install Laravel installer globally, if you haven't installed it yet, then run

composer global require laravel/installer

to install it globally in your computer.
Now to create a Laravel application with Laravel install, just run

laravel new appName

make sure you replace appName with the name of your application. You can also clone the Laravel official repository on Github to get started but I won't cover that.
Great, now let's

cd appName

into our application directory. As a side note, the application I am going to build throughout this series is called Africa Data API.

Create a git repo

You can use your favorite git service provider, throughout this series am going to use Github. So, sign in to your git service account or sign up if you don't have an account yet and create a private or public repository. If you've not used git before then I would recommend you stop reading this article and learn git basics because I am going to use git. Once you've created the repository, switch back to your project directory, and open the terminal.
Run

git init

This command will create a new empty repository in your application directory.

git commit -m "First commit"

This is our first commit, the command adds a commit with a commit message. It is good practice to add a meaningful commit message every time you're committing your work and commit more often after a major or a minor development change.

git branch -M main

This command simply changes the default repository to main instead of master. More on Github repository default branch renaming

git remote add origin project-github-repository-url

git remote add adds a remote git repository. origin is the name of remote it can be named anything else but it is the most commonly used or the most recommended default remote name, project-github-repository-url is the repository ssh or HTTPS URL for your project.

git push -u origin main

This command pushes your commits to your remote repository which is origin and to the specified branch which is main in our case, -u flag sets the main branch in origin remote as upstream branch.

That's it for the first article stay tuned for the next article or follow me on twitter for updates. You can find the application code here github.com/marvinhosea/africa-data-api.

Devs.Africa

We're building devs.africa and you can join the waiting list in case you plan to hire developers from Africa or get opportunities and resources as a developer.