profDevA / laravel-article-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel Assetsment

What I have done

I created a new Laravel 9 project and implemented REST API to add new Article data, retrieve articles with pagination and retrieve a single article with a temporary image URL. And created a cron job that deletes articles older than 30 days every hour.

Prerequisites

Set up project

1. Clone the git repository

git clone https://github.com/profDevA/laravel-article-demo.git

2. Install packages

composer install

3. Create .env file

cp .env.example .env

Please set database name, database user and password in .env file.

4. Generate App key

php artisan key:generate

5. Create tables

php artisan migrate

Run API server

php artisan serve

This command will run the server on http://localhost:8000

Run scheduler (for delete old articles)

Run the scheduler locally

php artisan schedule:work

Run the scheduler on remote server

If you deploy your app on remote server, you can run it as follows

 cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

API endpoints

Type Endpoint Description
GET|HEAD /api/article Get articles with pagination (10 items)
POST /api/article Create and save a new article record from inputs. Upload an image in private folder.
GET /api/article/{article} Get a single article with temporary image URL.

About


Languages

Language:PHP 82.5%Language:Blade 16.3%Language:Shell 0.9%Language:JavaScript 0.3%