wire-elements / spotlight

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
MIT License
927 stars 72 forks source link

Suggestions on start #62

Closed nam-co closed 2 years ago

nam-co commented 3 years ago

Hi @PhiloNL , I got some ideas I hope you find them interesting

  1. Function suggestion on open (some people prefer clicking than typing), this could be used to show for example: latest visited pages , last search or last used function
  2. Be able to search on open (from the start), for example: show results of clients and invoices (keeping functions on the top)

Thanks for the package

luigi-dv commented 2 years ago

Hi,

First of all you must implement the last visited pages to store in your project. And the next will be load this last visited pages in to the spotlight constructor class.

I recommend to use Redis Connection for this functionality like this:


<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redis;

class LastSeen
{

    public function handle($request, Closure $next)
    {
        if (!Auth::check()) {
            return $next($request);
        }

        $redis = Redis::connection();

        $key = 'last_seen_' . Auth::id();
        $value = (new \DateTime())->format("Y-m-d H:i:s");

        $redis->set($key, $value);

        return $next($request);
    }
}

Function to get the last seen information:

public function lastSeen() {
       $redis = Redis::connection();
       return $redis->get('last_seen_' . $this->id);        
}

You can then retrieve the last seen information on a user by calling the method as such:


$user->lastSeen();

I'm working on it and do PR I this next days.