yaroslawww / laravel-recently-viewed Goto Github PK
View Code? Open in Web Editor NEWFunctionality to save/get in session recently viewed entities
License: Other
Functionality to save/get in session recently viewed entities
License: Other
I have a different database where I want to keep the recently_viewed table. Is there a recommended way to do this? I cannot currently as I don't see anwhere where I can specify a different connection.
Hi, First of all thank for this awesome package.
I don't think this is really an issue with your package but i just don't know exactly how to use this. I'm having trouble with the foreach loop. This is what i'm doing right now, but it doesn't always return the correct result.
Can you tell me how to do this the right way?
@foreach(Session::get('recently_viewed')['App\Models\Product'] as $id)
<?php $product = $products->get($id); ?>
{{ $product->title }}
{{ $product->category->name }}
{{ $product->price }}
@endforeach
Hi there, was hoping to check this out for a current app, but the PHP requirements don't line up. Just FYI. :)
Using the package with the persist storage setting as true will throw an error if you try to fetch the recent views for a model that does not have any views yet.
The solution seems simple, adding a default array value here:
$keys = session()->get(config('recently-viewed.session_prefix') . '.' . get_class($viewable));
to
$keys = session()->get(config('recently-viewed.session_prefix') . '.' . get_class($viewable), []);
Putting more information in case I'm missing something else,
Stacktrace:
local.ALERT: TypeError: Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given, called in /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 919 and defined in /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3078
Stack trace:
#0 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(919): Illuminate\Database\Query\Builder->cleanBindings()
#1 /vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(23): Illuminate\Database\Query\Builder->whereIn()
#2 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1406): Illuminate\Database\Eloquent\Builder->forwardCallTo()
#3 /vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(23): Illuminate\Database\Eloquent\Builder->__call()
#4 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1734): Illuminate\Database\Eloquent\Model->forwardCallTo()
#5 /vendor/yaroslawww/laravel-recently-viewed/src/Models/Traits/CanBeViewed.php(19): Illuminate\Database\Eloquent\Model->__call()
#6 /vendor/yaroslawww/laravel-recently-viewed/src/RecentlyViewed.php(53): App\Models\Model->whereRecentlyViewedIn()
#7 /vendor/yaroslawww/laravel-recently-viewed/src/RecentlyViewed.php(71): RecentlyViewed\RecentlyViewed->getQuery()
#8 /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): RecentlyViewed\RecentlyViewed->get()
if the user logged out, and then logs in without visiting a "subject" page to create a new recently_viewed session, all data saved on the "recent_views" table will be erased
Where I need to put \RecentlyViewed\PersistManager::enableMigrations()
?
Why not just use php artisan vendor:publish --provider="RecentlyViewed\ServiceProvider" --tag="migrations"
Is there a way to keep the recently viewed even after logged out so that next time it is still there when logging back in?
Can you update this in RecentlyViewed.php
protected function getViewer(): ?Viewer
{
if (($user = Auth::user())
&& $user instanceof Viewer) {
return $user;
}
return null;
}
protected function getViewer(): ?Viewer
{
foreach (array_keys(config('auth.guards')) as $guard) {
if (($user = Auth::guard($guard)->user()) && $user instanceof Viewer) {
return $user;
}
}
return null;
}
I encountered this error while using pgsql, but it works fine in mysql
this is the source of the problem, the field function is not found in pgsql
->orderByRaw("FIELD({$this->getKeyName()}, {$values_ordered})");
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.