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.
git clone https://github.com/profDevA/laravel-article-demo.git
composer install
cp .env.example .env
Please set database name, database user and password in .env
file.
php artisan key:generate
php artisan migrate
php artisan serve
This command will run the server on http://localhost:8000
php artisan schedule:work
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
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. |