The News Aggregator Backend is a Larevl-based application that fetch News from different sources and provides users the ability to view news feeds, search for news with customizable filters, and set personalized news feed preferences. The app also includes features for user registration and login, allowing users to manage their preferences and stay updated with the latest news from diffrent sources.
The challenge of fetching news from multiple sources, each with different endpoints and response structures, can be approached in several ways. In this solution, I’ve implemented a configuration-driven approach using the newsproviders.php file.
This configuration allows you to easily add new news provider endpoints and map their responses to database fields without needing to modify any core code. Simply update the configuration with new provider details, including the API URL, parameters, and response mappings.
Here’s an example configuration for a news provider:
'providers' => [
'nytimes' => [
'url' => 'https://api.nytimes.com/svc/search/v2/articlesearch.json',
'date_key' => 'begin_date',
'request_body' => [
'begin_date' => '',
'api-key' => '',
],
'response_path' => 'response.docs',
'fields_map' => [
'title' => 'headline.main',
'url' => 'web_url',
'published_at' => 'pub_date',
'category' => 'section_name',
'type' => 'type_of_material',
'source_id' => '_id',
'author' => 'byline.original'
],
]
],
- PHP: 8.1 or higher
- Composer: Latest version
- Database: MySQL
-
Clone the Repository
git clone [https://github.com/ahmedsadekdevphp/News-Aggregator.git] cd news
-
Install Dependencies
composer install
-
Environment Setup
cp .env.example .env php artisan key:generate
-
Configure Environment Variables
Edit the.env
file with your database and other configuration settings:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database DB_USERNAME=your_username DB_PASSWORD=your_password
-
Run Migrations
php artisan migrate
-
Clear Application Cache
php artisan cache:clear php artisan route:clear php artisan config:clear php artisan view:clear
-
run laravel Scedule
php artisan schedule:run
-
Ftech News Command
php artisan news:fetch