It's simple.
Using visits
helper as:
visits($model)->{method}()
Where:
- $model: is any Eloquent model from your project.
- {method}: any method that is supported by this library, and they are documented below.
- You can track multiple kinds of visits to a single model using the tags as
visits($model,'tag1')->increment();
You can add a visits
method to your model class:
class Post extends Model
{
//....
public function vzt()
{
return visits($this);
}
}
Then you can use it as:
$post = Post::find(1);
$post->vzt()->increment();
$post->vzt()->count();
If you are using visits with eloquent as engine (from config/visits.php; engine => \Awssat\Visits\DataEngines\EloquentEngine::class) then you can add a relationship method to your models.
class Post extends Model
{
//....
public function visits()
{
return visits($this)->relation();
}
}
//then:
Post::with('visits')->get();
Prev: < Installation