Skip to content

Latest commit

 

History

History
205 lines (175 loc) · 5.89 KB

README.md

File metadata and controls

205 lines (175 loc) · 5.89 KB

Laravel Logo

Build Status Total Downloads Latest Stable Version License

About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

Laravel is accessible, powerful, and provides tools required for large, robust applications.

Setup do Projeto:

Instalando dependencias

  php composer install

Configurando banco de dados

  • Verifique seu arquivo .env com as configurações corretas com o seu banco de dados
  DB_CONNECTION=mysql
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=laravel
  DB_USERNAME=root
  DB_PASSWORD=

Rodando as migrations e seeders:

  php artisan migrate --seed

Iniciando servidor

  php artisan serve

Documentação das querys

Buscar posts e mostrar a qual usuário pertence

  Post::with('user')->get()

Buscar produtos e mostrar a qual usuário pertence

  Product::with('user')->get()

Buscar posts e produtos que um usuário específico cadastrou

  User::with('posts','products')->find(1)

Buscar produtos especificando uma faixa de preços

  Product::whereBetween('price', [100,500])->orderBy('price', 'desc')->get()

Documentação da API

Realizar register

  POST api/register

Exemplo:

  curl -XPOST http://127.0.0.1:8000/api/register -H "Content-Type: application/json" -d "{\"name\":\"Pedro Moreira\", \"email\": \"[email protected]\", \"password\": \"admin123123\", \"password_confirmation\": \"admin123123\"}"

Realizar login

  POST api/login

Exemplo:

    curl -XPOST http://127.0.0.1:8000/api/login -H "Content-Type: application/json" -d "{\"email\": \"[email protected]\", \"password\": \"admin123123\"}"

OBS: Returned a token.

Visualizar Posts

    GET api/posts

Visualizar um Post

    GET api/posts/{id}

Exemplo:

  curl -XGET http://127.0.0.1:8000/api/posts/1

Cadastrar um Post

    POST api/posts

Exemplo:

    curl -XPOST http://127.0.0.1:8000/api/posts -H "Content-Type: application/json" -H "Authorization: Bearer <login_token>" -d "{\"title\": \"Example Title\", \"content\": \"Example body of post.\"}"

Atualizar um Post

  PUT/PATCH api/posts/{id}

Exemplo:

  curl -XPUT http://127.0.0.1:8000/api/posts/1 -H "Content-Type: application/json" -H "Authorization: Bearer <login_token>" -d "{\"title\": \"Example title updated\", \"content\": \"Example body of post updated\"}"

Deletar um Post

  DELETE api/posts/{id}

Exemplo:

  curl -XDELETE http://127.0.0.1:8000/api/posts/1 -H "Authorization: Bearer <login_token>"

Listar users

  GET api/users

Exemplo:

  curl -XGET http://127.0.0.1:8000/api/users -H "Authorization: Bearer <login_token>"

Atualizar um User

  PUT/PATCH api/users/{id}

Exemplo:

  curl -XPUT http://127.0.0.1:8000/api/users/1 -H "Content-Type: application/json" -H "Authorization: Bearer <login_token>" -d "{\"name\": \"Joao Pedro Moreira\", \"email\": \"[email protected]\", \"password\": \"adminadmin\", \"password_confirmation\": \"adminadmin\"}"

Deletar um User

  DELETE api/users/{id}

Exemplo:

  curl -XDELETE http://127.0.0.1:8000/api/users/1 -H "Authorization: Bearer <login_token>"

Listar produtos

  GET api/products

Exemplo:

  curl -XGET http://127.0.0.1:8000/api/products -H "Authorization: Bearer <login_token>"

Listar produtos com paginação

  GET api/products

Exemplo:

  curl -XGET http://127.0.0.1:8000/api/products?per_page=1 -H "Authorization: Bearer <login_token>"

Mostrar produto

  GET api/products

Exemplo:

  curl -XGET http://127.0.0.1:8000/api/products/{product} -H "Authorization: Bearer <login_token>"

Atualizar um produto

  PUT/PATCH api/products/{product}

Exemplo:

  curl -XPUT http://127.0.0.1:8000/api/products/{product} -H "Content-Type: application/json" -H "Authorization: Bearer <login_token>" -d "{\"name\": \"Example name Prod\", \"description\": \"Example description Prod\", \"price\": 1234.90}"

Deletar um produto

  DELETE api/products/{product}

Exemplo:

  curl -XDELETE http://127.0.0.1:8000/api/products/{product} -H "Authorization: Bearer <login_token>"