PHP code example of jm-inc / laravel-viewable

1. Go to this page and download the library: Download jm-inc/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/ */

    

jm-inc / laravel-viewable example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use JM\Viewable\InteractsWithViews;

class Post extends Model
{
    use HasFactory, InteractsWithViews;
}



namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
    public function show(Post $post)
    {
        // ...
        $post->viewed();
        // ...
    }
}