Skip to content

laravel 8, passport api multi auth of admin & user both with basic blog CRUD with category & tag CRUD on different api controllers

License

Notifications You must be signed in to change notification settings

ashraf-kabir/passport_test

Repository files navigation

passport_test

commands

git clone https://github.com/ashraf-kabir/passport_test
cd passport_test
composer require laravel/passport
php artisan migrate
php artisan passport:install
php artisan serve

schema (custom models)

users: name, email, password ... timestamps

admins: name, email, password ... timestamps

blogs: title, description, category_id, tag_id, user_id, status, ... timestamps

categories: name, status, ... timestamps

tags: name, status, ... timestamps


info

passport multi auth used with guard, scope middlewares.

Two separate api route group created for 2 user roles.

admin cannot view users api route, same goes for users.

admin can register, login& logout. admin can add categories, tags. admin can view all blogs, categories, tags & users list admin can delete categories & tags.

user can register, login & logout. user can add blogs. user can view all blogs list. user can delete only his added blogs. user can search blogs by blog title, category name, tag name. user can view his profile details.

on logout token revoked


routes

user:

  1. user->register

    method: POST

    http://localhost:8000/api/user/register

    params:

    name
    email
    password
    password_confirmation


  2. user->login

    method: POST

    http://localhost:8000/api/user/login

    params:

    email
    password

    copy token and add on Bearer when necessary


  3. user->logout

    method: POST

    http://localhost:8000/api/user/logout

    on headers pass Bearer token


  4. user->blogs->list

    method: GET

    http://localhost:8000/api/user/blogs

    pass Bearer token


  5. user->blogs->add

    method: POST

    http://localhost:8000/api/user/blogs/add

    params:

    title
    description
    status
    category_id
    tag_id

    (title & description is string & text respectively. status, category_id, tag_id are all integer. status can be 1, 0 meant for active, inactive. All params are mandatory here)

    note: on headers pass the Bearer token only. (auto capture user_id from auth after submit)


  6. user->blogs->delete

    method: GET

    http://localhost:8000/api/user/blogs/delete/{id}

    on headers pass the Bearer token only


  7. user->blogs->search

    method: GET

    http://localhost:8000/api/user/blogs/search

    params:

    search_term

    note: search by blog title, category name & tag name

    on headers pass the Bearer token only


  8. user->profile details view

    method: GET

    http://localhost:8000/api/user/profile

    on headers pass the Bearer token only


admin:

  1. admin->register

    method: POST

    http://localhost:8000/api/admin/register

    params:

    name
    email
    password
    password_confirmation


  2. admin->login

    method: POST

    http://localhost:8000/api/admin/login

    params:

    email
    password

    copy token and add on Bearer when necessary


  3. admin->logout

    method: POST

    http://localhost:8000/api/admin/logout

    on header pass Bearer token


  4. admin->blogs->list

    method: GET

    http://localhost:8000/api/admin/blogs

    on header pass Bearer token


  5. admin->categories->list

    method: GET

    http://localhost:8000/api/admin/categories

    on header pass Bearer token


  6. admin->categories->add

    method: POST

    http://localhost:8000/api/admin/categories/add

    params:

    name
    status

    name->string, status->integer(1, 0)->(active, inactive)

    note: both params are mandatory & on header pass Bearer token


  7. admin->categories->delete

    method: GET

    http://localhost:8000/api/admin/categories/delete/{id}

    pass id url

    on header pass Bearer token


  8. admin->tags->list

    method: GET

    http://localhost:8000/api/admin/tags

    on header pass Bearer token


  9. admin->tags->add

    method: POST

    http://localhost:8000/api/admin/tags/add

    params:

    name
    status

    name->string, status->integer(1, 0)->(active, inactive)

    note: both params are mandatory & on header pass Bearer token


  10. admin->tags->delete

    method: GET

    http://localhost:8000/api/admin/tags/delete/{id}

    pass id url

    on header pass Bearer token


  11. admin->dashboard (to view customers list)

    method: GET

    http://localhost:8000/api/admin/dashboard

    on header pass Bearer token

    note: it will return the users list from users table

About

laravel 8, passport api multi auth of admin & user both with basic blog CRUD with category & tag CRUD on different api controllers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published