Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

conwork/api-laravel

Repository files navigation

Setup

Requirements

Laravel 11.x

PHP >= 8.2

Enabled PHP Extensions:

enable curl & fileinfo PHP extensions in php.ini file

extension=curl
extension=fileinfo

source: https://laravel.com/docs/11.x/deployment#server-requirements

Generate environment variables file:

Copy and customize repository .env.example as .env.

Install composer dependencies

composer install

Generate App key:

php artisan key:generate

Adds generated key to .env file.

Run migrations

php artisan migrate

Run seeders

php artisan db:seed

Seeds user with the .env (USER_*) data

Application

routes

  • GET / (sanctum authenticated)
  • POST /auth/login { "email": "[email protected]", "password": "password" }
  • GET /auth/logout (sanctum authenticated)

Documentation

  • GET /docs
  • GET /docs.json

/insomina-document.json file also available.

Tasks

1. Create Article migration & model

Props:

  • title: string (255)
  • article: text

Relations:

  • Article->author()
  • User->articles()

2. Create Article routes (sanctum authenticated)

Article input validation:

  • title: required && max-length: 255
  • article: required

Routes:

  • List articles:
    GET /articles
  • Create article (author is the authenticated-request-user):
    POST /articles
  • Show article:
    GET /articles/{article}
  • Update article (optional: authorize only if author is the authenticated-request-user):
    PUT | PATCH /articles/{article}
  • Delete article (optional: authorize only if author is the authenticated-request-user):
    DELETE /articles/{article}

3. Create UserPreferences middleware and apply to sanctum auth routes

Get preferences from authenticated request user ($user->preferences), check for locale preference and change app lang / locale correspondingly.

config('app.available_locales') contains the application available languages: ['en', 'es']

Prepared translations for Article routes responses can be found under:

  • /lang/en/article.php | /lang/es/article.php:
    • article.index.success
    • article.store.success
    • article.show.success
    • article.update.success
    • article.delete.success

4. Create app:revoke-all-user-tokens {--user_id=} command

Delete all User personal access tokens for the given --user_id.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages