GithubHelp home page GithubHelp logo

tursunboyevjahongir / laravel_api Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 0.0 2.87 MB

Easy Rest api with Laravel

Shell 0.02% PHP 99.83% Dockerfile 0.15%
api laravel mysql php docker oop-php rest-api php8 laravel-api

laravel_api's Introduction

Used

.github/workflows/docker-image.yml Testing

In Project

CRUD [ Create Read Update Delete ]

Global postman documentation

Possible params for get method

params are not required
  • list_type->string[pagination,collection] default pagination
  • columns->string default all columns. separated from each other by a comma(,)
    • host.com/products?columns=id,name,description,... add more with ,
  • relations->string default null
    • multi relations=parent;author;... add more with ;
    • And you can multi relationship with dot notation relations=products.mainImage;author;...
  • limit->integer default 30
    • working with colection
  • per_page->integer default 30
    • working with pagination
  • conditions->string|array default null
    • the conditions are and with each other
    • string condition=column:value;column2:value2
    • array condition[column]=value&column[column2]=value2
      https://host.com/users?conditions[first_name]=Jahongir&conditions[last_name]=Jahongir&conditions[author.middle_name]=Jahongir
      or you can use this on one variable
      https://host.com/users?condition=first_name:Jahongir;last_name:Tursunboyev;author.middle_name=doe
  • not_conditions-> array default null
    • conditions and with each other. and the result will be reversed
    • not_conditions reverse conditions
  • or_conditions-> array default null
    • the conditions are or with each other
    • or_conditions from request, if any of them are equal it will work
  • between->array default null
    • array accessive key=column value=int or date between FROMtoTO,if only FROM is given, it is taken from FROM to the end. if only TO(toTO) is given, it takes from start to TO . if between(FROMtoTO) is given, it takes all the data inside FROMtoTO
    • {{host}}/users?between[price]=100to200&between[created_at]=2022-11-10&between[amount]=to200
  • not_between->not_between reverse between
  • is_active->boolean[or 0,1] default all
    • or conditions[is_active]=0 [0,1]\
  • search->string default null
  • searchFilds->string array default null.
    • string
    https://host.com/users?search=John&searchFilds=first_name,last_name,author.first_name
    • array
    https://host.com/users?search=John&searchFields[]=first_name&searchFields[]=last_name&searchFields[]=author.first_name
  • orderBy->string default id
  • sortBy-> string[asc,desc] default desc
  • appends->string default null
    • working with collection
    • multi appends=full_name;appends2;... add more with ;
  • pluck->string default null
  • only_deleted->boolean[0,1] default 0(false)

Sort, OrderBy

host.com/directory?orderBy=column

https://host.com/products?orderBy=name&sortBy=ASC

[
    {
        "id": 3,
        "category_id": 3,
        "name": "Apple"
    },
    {
        "id": 1,
        "name": "Grape"
    },
    {
        "id": 2,
        "name": "Kiwi"
    }
]

Sorting through relation's column only works with belongsTo relation.Does not work multi-depth dot notation.Only works with one dot(one relation)

host.com/directory?orderBy=relation.column

https://host.com/products?orderBy=category.name&sortedBy=desc

Query will have something like this

...
LEFT JOIN categories ON products.category_id = categories.id
...
ORDER BY categories.name
...

Multi orderBy

host.com/directory?orderBy=column;relation.column;relation2.column2...

https://host.com/products?orderBy=name;category.name&sortedBy=desc

Product::leftJoin("categories", "products.category_id", "categories.id")->orderBy('name','desc')->orderBy('categories.name','desc');
...
Model::leftJoin("relationTable", "selfTable.foreignKey", "relationTable.ownerKey")->orderBy('column')->orderBy('relationTable.column')...;

Headers

  • Accept-Language:ru [ru,uz,en] default ru
  • Accept:application/json required

Response

{
    "code": 200,
    "message": "OK",
    "data": {
         //data
    }
}

Error Response

{
    "code": 422,
    "message": "The given data was invalid.",
    "data": {
        "errors": {
             //Errors
        }
     }
}

  • code->int [200,201,204,401,403,404,422,500]
  • message->string default ''
    • the language of the message will be changed by the header Accept-Language
  • data->array|Collection default []
Example
- Profile RU
- User CRUD --- set role
- Category CRUD
- Role CRUD //todo
- Product CRUD //todo

laravel_api's People

Contributors

nizomiddinzaripov avatar tursunboyevjahongir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.