Giter Club home page Giter Club logo

laravel-disqus's Introduction

Disqus comments for your resources

Simple, probably unneeded, package to add the ability to easily add Disqus comments on your site. You just need to implement the HasDisqus interface on your model, add disqus to your services config file and add a line to your view.

Installation

Composer require:

composer require lagbox\disqus

Add the service provider to your config/app.php $providers array:

lagbox\disqus\DisqusServiceProvider::class,

If you would like to modify the comments view, you can publish it:

php artisan vendor:publish --provider="lagbox\disqus\DisqusServiceProvider"

Configuration

After you have signed up with Disqus you only need the domain that your embed script is located at.

Add to your config/services.php:

'disqus' => [
    'domain' => 'yoursite.disqus.com'
]

Implementing the Interface

You can add the lagbox\disqus\Traits\HasDisqus trait to implement the first method of the interface getDisqus. This method of the trait gathers the data from disqusUrl and disqusIdentifier into an associative array.

use lagbox\disqus\Interface\HasDisqus;
use lagbox\disqus\Traits\HasDisqus as HasDisqusTrait;

class YourModel extends Model implements HasDisqus
{
    use HasDisqusTrait;

    ...

    public function disqusUrl()
    {
        // full url to your resource
        return route('articles.show', $this);
    }

    public function disqusIdentifier()
    {
        // the unique identifier for this resource for disqus purposes
        return 'blog/'. $this->slug;
    }
}

Now your model is ready to return the needed information for the disqus comments script.

Views

You can use the blade directive that the Service Provider adds:

@disqus($hasDisqusModel)

Or call the helper function directly:

{!! disqusScript($hasDisqusModel) !!}

<?php echo disqusScript($hasDisqusModel); ?>

Just make sure to pass a model that implements the HasDisqus interface.

Misc.

Literally you can just do all of this yourself. The Disqus javascript only requires 3 pieces of information.

This is just here as a usable example.

laravel-disqus's People

Contributors

lagbox avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.