PHP code example of balajidharma / laravel-viewable

1. Go to this page and download the library: Download balajidharma/laravel-viewable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

balajidharma / laravel-viewable example snippets



namespace BalajiDharma\LaravelForum\Models;

use BalajiDharma\LaravelViewable\Traits\HasViewable;
use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    use HasViewable;
	

public function show(Thread $thread)
{
    $thread->record();
    

'models' => [
    'viewable' => BalajiDharma\LaravelViewable\Models\Viewable::class,
],

'table_names' => [
    'viewable' => 'views',
],

'ignore_bots' => true,

'honor_dnt' => false,

'unique_ip' => true,
'unique_session' => true,
'unique_viewer' => true,

'increment_model_view_count' => false,
'increment_model_column_name' => 'view_count',

'ignored_ip_addresses' => [
    //'127.0.0.1',
],


namespace BalajiDharma\LaravelForum\Models;

use BalajiDharma\LaravelViewable\Traits\HasViewable;
use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    use HasViewable;

    protected $ignore_bots = true;

    protected $honor_dnt = true;

    protected $unique_session = false;

    protected $unique_ip = false;

    protected $unique_viewer = false;

    protected $increment_model_view_count = true;

    protected $increment_model_column_name = 'view_count';

    protected $ignored_ip_addresses = [
        '127.0.0.1',
        '0.0.0.0'
    ]

bash
php artisan vendor:publish --provider="BalajiDharma\LaravelViewable\ViewableServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="BalajiDharma\LaravelViewable\ViewableServiceProvider" --tag="config"