Skip to main content

RSS FEED Laravel

RSS FEED IN LARAVEL


Installation

The Laravel 5/6/7 Feeds Service Provider can be installed via Composer by requiring the willvincent/feeds package in your project's composer.json.

{
    "require": {
        "willvincent/feeds": "1.1.*"
    }
}


Configuration
If you're using Laravel 5.5 or newer you may skip the next step.

To use the Feeds Service Provider, you must register the provider when bootstrapping your Laravel application.

Find the providers key in your config/app.php and register the Service Provider.

    'providers' => [
        // ...
        willvincent\Feeds\FeedsServiceProvider::class,
    ],


Find the aliases key in your config/app.php and register the Facade.

    'aliases' => [
        // ...
        'Feeds'    => willvincent\Feeds\Facades\FeedsFacade::class,
    ],

Usage
Run php artisan vendor:publish --provider="willvincent\Feeds\FeedsServiceProvider" to publish the default config file, edit caching setting withing the resulting config/feeds.php file as desired.

See SimplePie Documentation for full API usage documentation.

The make() accepts 3 paramaters, the first parameter is an array of feed URLs, the second parameter is the max number of items to be returned per feed, and while the third parameter is a boolean which you can set to force to read unless content type not a valid RSS.

$feed = Feeds::make('http://feed/url/goes/here');

Note: In Laravel 5 and newer, Facades must either be prefixed with a backslash, or brought into scope with a use [facadeName] declaration.
Example controller method, and it's related view:
Controller:

  public function demo() {
    $feed = Feeds::make('http://blog.case.edu/news/feed.atom');
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

or Force to read unless content type not a valid RSS

  public function demo() {
    $feed = Feeds::make('http://blog.case.edu/news/feed.atom', true); // if RSS Feed has invalid mime types, force to read
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

Multifeeds example controller method, and it's related view:
Controller:

  public function demo() {
    $feed = Feeds::make([
        'http://blog.case.edu/news/feed.atom',
        'http://tutorialslodge.com/feed'
    ], 5);
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

or Force to read unless content type not a valid RSS

  public function demo() {
        $feed = Feeds::make(['http://blog.case.edu/news/feed.atom',
        'http://tutorialslodge.com/feed'
    ], 5, true); // if RSS Feed has invalid mime types, force to read
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

View:

@extends('app')

@section('content')
  <div class="header">
    <h1><a href="{{ $permalink }}">{{ $title }}</a></h1>
  </div>

  @foreach ($items as $item)
    <div class="item">
      <h2><a href="{{ $item->get_permalink() }}">{{ $item->get_title() }}</a></h2>
      <p>{{ $item->get_description() }}</p>
      <p><small>Posted on {{ $item->get_date('j F Y | g:i a') }}</small></p>
    </div>
  @endforeach
@endsection 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Comments

Popular posts from this blog

REMOVE ANY TIMEZONE FROM DATE AND TIME USING LARAVEL

                            REMOVE ANY TIMEZONE FROM DATE AND TIME STEP 1:- INSTALL CARBON DATE  Use the following command to install with composer. composer require nesbot/carbon Step 2:- Use this code $date = Carbon::parse('Thu, 28 May 2020 02:42:45 -0400'); dump($date->toDateTimeString()); dump($date->format('Y-m-d')); dump($date->format('Y-m-d H:i:s')); dump($date->timezone->getName()); dump($date->timestamp); output:-  Thu, 28 May 2020 02:42:45

Laravel 5.7 - Stripe Payment Gateway By Captain Laravel

Presented By Captain Laravel STEP 1:  we need to install stripe-php via the Composer package manager, so one your terminal and fire bellow command:   Command:-  composer require stripe/stripe-php STEP 2 :- Now, we need to set stripe key and secret. so first you can go on  Stripe  website and create development stripe account key and secret and add bellow: .env STRIPE_KEY=pk_test_reFxwbsm9cdCYYYBbynUfxAR STRIPE_SECRET=sk_test_iQMFWtUUTTBGFECAtgApY routes/api.php Route::get('stripe', 'StripePaymentController@stripe'); Route::post('stripe', 'StripePaymentController@stripePost')->name('stripe.post');