Giter Site home page Giter Site logo

laravel-recently-viewed's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-recently-viewed's Issues

Persist storage in separate database

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.

How do i use this in a blade view?

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

Update for PHP 8?

Hi there, was hoping to check this out for a current app, but the PHP requirements don't line up. Just FYI. :)

Exception when there's not a matching record for a model in the database

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()

How to use persist storage

Where I need to put \RecentlyViewed\PersistManager::enableMigrations()?
Why not just use php artisan vendor:publish --provider="RecentlyViewed\ServiceProvider" --tag="migrations"

persist storage with different guards not working

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;
}

ERROR: function field(bigint, integer) does not exist

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})");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.