• This repository has been archived on 28/Sep/2022
  • Stars
    star
    1,186
  • Rank 37,940 (Top 0.8 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Exemplary real world backend API built with Laravel

Laravel Example App

Build Status Gitter GitHub stars GitHub license

Example Laravel codebase containing real world examples (CRUD, auth, advanced patterns and more) that adheres to the RealWorld spec and API.

This repo is functionality complete β€” PRs and issues welcome!


Getting started

Installation

Please check the official laravel installation guide for server requirements before you start. Official Documentation

Alternative installation is possible without local dependencies relying on Docker.

Clone the repository

git clone [email protected]:gothinkster/laravel-realworld-example-app.git

Switch to the repo folder

cd laravel-realworld-example-app

Install all the dependencies using composer

composer install

Copy the example env file and make the required configuration changes in the .env file

cp .env.example .env

Generate a new application key

php artisan key:generate

Generate a new JWT authentication secret key

php artisan jwt:generate

Run the database migrations (Set the database connection in .env before migrating)

php artisan migrate

Start the local development server

php artisan serve

You can now access the server at http://localhost:8000

TL;DR command list

git clone [email protected]:gothinkster/laravel-realworld-example-app.git
cd laravel-realworld-example-app
composer install
cp .env.example .env
php artisan key:generate
php artisan jwt:generate 

Make sure you set the correct database connection information before running the migrations Environment variables

php artisan migrate
php artisan serve

Database seeding

Populate the database with seed data with relationships which includes users, articles, comments, tags, favorites and follows. This can help you to quickly start testing the api or couple a frontend and start using it with ready content.

Open the DummyDataSeeder and set the property values as per your requirement

database/seeds/DummyDataSeeder.php

Run the database seeder and you're done

php artisan db:seed

Note : It's recommended to have a clean database before seeding. You can refresh your migrations at any point to clean the database by running the following command

php artisan migrate:refresh

Docker

To install with Docker, run following commands:

git clone [email protected]:gothinkster/laravel-realworld-example-app.git
cd laravel-realworld-example-app
cp .env.example.docker .env
docker run -v $(pwd):/app composer install
cd ./docker
docker-compose up -d
docker-compose exec php php artisan key:generate
docker-compose exec php php artisan jwt:generate
docker-compose exec php php artisan migrate
docker-compose exec php php artisan db:seed
docker-compose exec php php artisan serve --host=0.0.0.0

The api can be accessed at http://localhost:8000/api.

API Specification

This application adheres to the api specifications set by the Thinkster team. This helps mix and match any backend with any other frontend without conflicts.

Full API Spec

More information regarding the project can be found here https://github.com/gothinkster/realworld


Code overview

Dependencies

  • jwt-auth - For authentication using JSON Web Tokens
  • laravel-cors - For handling Cross-Origin Resource Sharing (CORS)

Folders

  • app - Contains all the Eloquent models
  • app/Http/Controllers/Api - Contains all the api controllers
  • app/Http/Middleware - Contains the JWT auth middleware
  • app/Http/Requests/Api - Contains all the api form requests
  • app/RealWorld/Favorite - Contains the files implementing the favorite feature
  • app/RealWorld/Filters - Contains the query filters used for filtering api requests
  • app/RealWorld/Follow - Contains the files implementing the follow feature
  • app/RealWorld/Paginate - Contains the pagination class used to paginate the result
  • app/RealWorld/Slug - Contains the files implementing slugs to articles
  • app/RealWorld/Transformers - Contains all the data transformers
  • config - Contains all the application configuration files
  • database/factories - Contains the model factory for all the models
  • database/migrations - Contains all the database migrations
  • database/seeds - Contains the database seeder
  • routes - Contains all the api routes defined in api.php file
  • tests - Contains all the application tests
  • tests/Feature/Api - Contains all the api tests

Environment variables

  • .env - Environment variables can be set in this file

Note : You can quickly set the database information and other variables in this file and have the application fully working.


Testing API

Run the laravel development server

php artisan serve

The api can now be accessed at

http://localhost:8000/api

Request headers

Required Key Value
Yes Content-Type application/json
Yes X-Requested-With XMLHttpRequest
Optional Authorization Token {JWT}

Refer the api specification for more info.


Authentication

This applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using the Authorization header with Token scheme. The JWT authentication middleware handles the validation and authentication of the token. Please check the following sources to learn more about JWT.


Cross-Origin Resource Sharing (CORS)

This applications has CORS enabled by default on all API endpoints. The default configuration allows requests from http://localhost:3000 and http://localhost:4200 to help speed up your frontend testing. The CORS allowed origins can be changed by setting them in the config file. Please check the following sources to learn more about CORS.

More Repositories

1

realworld

"The mother of all demo apps" β€” Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more
TypeScript
78,236
star
2

react-redux-realworld-example-app

Exemplary real world application built with React + Redux
JavaScript
5,538
star
3

angular-realworld-example-app

Exemplary real world application built with Angular
TypeScript
5,079
star
4

vue-realworld-example-app

An exemplary real-world application built with Vue.js, Vuex, axios and different other technologies. This is a good example to discover Vue for beginners.
JavaScript
4,053
star
5

node-express-realworld-example-app

TypeScript
3,524
star
6

golang-gin-realworld-example-app

Exemplary real world application built with Golang + Gin
Go
2,440
star
7

aspnetcore-realworld-example-app

ASP.NET Core backend implementation for RealWorld
C#
1,872
star
8

django-realworld-example-app

Python
1,593
star
9

spring-boot-realworld-example-app

Example Spring codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.
Java
1,252
star
10

react-mobx-realworld-example-app

Exemplary real world application built with React + MobX
JavaScript
1,245
star
11

flask-realworld-example-app

Exemplary real world JSON API built with Flask (Python)
Python
891
star
12

elixir-phoenix-realworld-example-app

Exemplary real world application built with Elixir + Phoenix
Elixir
887
star
13

angularjs-realworld-example-app

Exemplary real world application built with Angular 1.5 + ES6
JavaScript
450
star
14

kotlin-spring-realworld-example-app

Kotlin
443
star
15

slim-php-realworld-example-app

Exemplary real world application built with Slim
PHP
428
star
16

rails-realworld-example-app

Ruby
427
star
17

realworld-starter-kit

Starter kit for new RealWorld framework implementations
407
star
18

swift

A better way to learn swift.
274
star
19

koa-knex-realworld-example

JavaScript
241
star
20

aurelia-realworld-example-app

Exemplary real world application built with Aurelia
JavaScript
184
star
21

ember-realworld

Ember.js RealWorld Implementation
JavaScript
182
star
22

web-components-realworld-example-app

Exemplary real world application built with Vanilla JS Web Components
JavaScript
171
star
23

scala-play-realworld-example-app

Exemplary real world application built with Scala 2.13 & Play
Scala
154
star
24

node-express-prisma-v1-official-app

Official real world application built with Node + Express + Typescript + Prisma
TypeScript
147
star
25

gcp-datastore-cloud-functions-realworld-example-app

Serverless GCP Cloud Functions + Datastore implementation of RealWorld Backend
JavaScript
144
star
26

cakephp-realworld-example-app

PHP
105
star
27

moleculer-node-realworld-example-app

Exemplary real world application built with Moleculer
JavaScript
103
star
28

clojurescript-reframe-realworld-example-app

Exemplary real world application built with ClojureScript + re-frame
Clojure
102
star
29

apprun-realworld-example-app

Exemplary real world application built with AppRun
TypeScript
101
star
30

fsharp-realworld-example-app

Exemplary real world application built with F#
F#
95
star
31

hapijs-realworld-example-app

Real World Hapi.JS + Mongoose backend implementations
JavaScript
78
star
32

clojurescript-keechma-realworld-example-app

Exemplary real world application built with ClojureScript & Keechma
Clojure
72
star
33

reasonml-realworld-example-app

Exemplary real world application built with ReasonML
Reason
59
star
34

conduit-bootstrap-template

HTML
33
star
35

dojo-realworld-example-app

Exemplary real world application built with Dojo2
TypeScript
29
star
36

angularfire-slack

JavaScript
27
star
37

QEWD-realworld-example-app

JavaScript
22
star
38

crizmas-mvc-realworld-example-app

Exemplary real world application built with Crizmas MVC (React)
JavaScript
17
star
39

express-prisma-official-app

TypeScript
14
star
40

jswiki

The wiki for modern Javascript terminology
HTML
13
star
41

conduit-angularjs-final

JavaScript
10
star
42

conduit-sass

HTML
8
star
43

conduit-django

Python
8
star
44

thinkdown

Preview markdown as it appears on https://thinkster.io
CSS
6
star
45

test-routes

JavaScript
6
star
46

conduit-react-client-final

JavaScript
4
star
47

conduit-rails4-api-final

Ruby
4
star
48

course-boilerplate

3
star
49

mean-stack-tutorial

3
star
50

realworld-api-action

GitHub Action running a Postman collection to test the compliance of a backend implementation of RealWorld specs
JavaScript
3
star
51

api-realworld

TypeScript
2
star
52

gothinkster.github.io

HTML
2
star
53

conduit-rails4

Ruby
2
star
54

conduit-rails

Ruby
2
star
55

conduit-angular

HTML
1
star
56

thinkster-author

Authoring site for Thinkster.io Authors
1
star
57

blog

Thinkster blog
1
star
58

imperial

JavaScript
1
star
59

conduit-api

TypeScript
1
star
60

transactional

1
star
61

realworld-e2e-tests

E2e test suite for RealWorld demo
JavaScript
1
star
62

realworld-tribe-angular-app

HTML
1
star
63

realworld-tribe-nestjs-app

TypeScript
1
star