Coder Social home page Coder Social logo

anzera-challenge's Introduction

Anzera Challenge with Laravel

Challenge details

What did I do?

  • Created models: User, Category, Product. Relation definitions:
    • User -> Product: One to Many
    • Product -> User: Many to One
    • Category -> Product: One to Many
    • Product -> Category: Many to One
  • Create foreign keys between products-users and products-categories tables in migration.
  • Defined CRUD REST route with extending Illuminate\Routing\Router class. The class is here: App\Extended\Router. This is added to here: bootstrap/app.php file. Detailed info is here.
  • Example middleware: App\Http\Middleware\PrintJsonResponse
  • Sessions disabled from App\Http\Kernel.

REST CRUD router

Example usage:
Route::restCrud('products', \App\Http\Controllers\Products::class);

This is creating these routes:

HTTP      URL                    CLASS METHOD     ROUTE NAME
------------------------------------------------------------------
GET       /products              index            products.index
POST      /products/create       create           products.create
GET       /products/{id}         read             products.read
PUT       /products/{id}         update           products.update
DELETE    /products/{id}         delete           products.delete

You can look to App\Extended\Router::restCrud() method for implementation.

Important thing about PUT (update) method: You must make HTTP POST request and you must add _method=PUT parameter to form parameters. Otherwise Laravel can't recognize the PUT method and routes blowing up.

What about authentication?

Challenge rules didn't required any authentication. But I just added and configured Passport library to project. We can use it if we need. In first we must write an Authentication controller for login-logout operations.

Bugs and TODOs

All of these must be solve:

  • Showing 404 if a request not validated. I must investigate this.
    • I investigated. findOrFail() method is causing this. If we don't find requested id from table then Laravel is opening 404 page. In API response I must catch this and print as JSON.

anzera-challenge's People

Contributors

kodmanyagha 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.