1. Go to this page and download the library: Download zing/laravel-eloquent-view 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/ */
zing / laravel-eloquent-view example snippets
use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Visit\Concerns\Visitor;
class User extends Model
{
use Visitor;
}
use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Visit\Concerns\Visitable;
class Subject extends Model
{
use Visitable;
}
use LaravelInteraction\Visit\Tests\Models\Subject;
/** @var \LaravelInteraction\Visit\Tests\Models\User $user */
/** @var \LaravelInteraction\Visit\Tests\Models\Subject $subject */
// Visit to Visitable
$user->visit($subject);
// Compare Visitable
$user->hasVisited($subject);
$user->hasNot
Visited($subject);
// Get visited info
$user->visitVisitors()->count();
// with type
$user->visitVisitors()->withType(Subject::class)->count();
// get visited subjects
Subject::query()->whereVisitedBy($user)->get();
// get subjects doesnt visited
Subject::query()->whereNotVisitedBy($user)->get();
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use LaravelInteraction\Visit\Tests\Models\Subject;
use Illuminate\Http\Resources\Json\JsonResource;
class AuctionController extends Controller
{
public function show($id, Request $request){
$subject = Subject::query()->findOrFail($id);
dispatch(function () use ($subject, $request) {
$subject->record($request);
})->afterResponse();
return new JsonResource($subject);
}
}