Skip to content

Instantly share code, notes, and snippets.

@benjamincrozat
Created November 28, 2023 09:17
Show Gist options
  • Save benjamincrozat/9867e131bb3d744d521a7befbd4889b1 to your computer and use it in GitHub Desktop.
Save benjamincrozat/9867e131bb3d744d521a7befbd4889b1 to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use App\GitHub;
use App\Models\Post;
use App\JobsCollector;
use Cloudinary\Cloudinary;
use App\Actions\TrackVisit;
use Barryvdh\Debugbar\Facades\Debugbar;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
use Algolia\AlgoliaSearch\RecommendClient;
use Cloudinary\Configuration\Configuration;
use WireElements\Pro\Components\Spotlight\Spotlight;
use WireElements\Pro\Components\Spotlight\SpotlightQuery;
use WireElements\Pro\Components\Spotlight\SpotlightResult;
class AppServiceProvider extends ServiceProvider
{
public function register() : void
{
$this->app->bind(
GitHub::class,
fn () => new GitHub(config('services.github.access_token'))
);
$this->app->bind(RecommendClient::class, function () {
return RecommendClient::create(
config('scout.algolia.id'),
config('scout.algolia.secret')
);
});
Spotlight::registerGroup('articles', 'Articles');
Spotlight::registerGroup('featured', 'Featured');
Spotlight::registerGroup('navigation', 'Navigation');
Spotlight::registerGroup('follow-me', 'Follow me');
Spotlight::setup(function () {
Spotlight::registerQueries(
SpotlightQuery::asDefault(function (string $query) {
if ($query && strlen($query) > 2) {
return Post::search($query)
->get()
->map(fn (Post $post) => SpotlightResult::make()
->setTitle($post->title)
->setGroup('articles')
->setAction('jump_to', ['path' => route('posts.show', $post)])
->setIcon('document'));
}
return collect([
SpotlightResult::make()
->setTitle('Promote your business')
->setGroup('featured')
->setAction('jump_to', ['path' => route('media-kit')])
->setIcon('megaphone'),
SpotlightResult::make()
->setTitle('The tools I use')
->setGroup('featured')
->setAction('jump_to', ['path' => route('posts.show', 'best-web-development-tools')])
->setIcon('wrench-screwdriver'),
SpotlightResult::make()
->setTitle('Free tools')
->setGroup('featured')
->setAction('jump_to', ['path' => route('home') . '#free-tools'])
->setIcon('gift'),
SpotlightResult::make()
->setTitle('Homepage')
->setGroup('navigation')
->setAction('jump_to', ['path' => route('home')])
->setIcon('home'),
SpotlightResult::make()
->setTitle('Latest articles')
->setGroup('navigation')
->setAction('jump_to', ['path' => route('posts.index')])
->setIcon('fire'),
SpotlightResult::make()
->setTitle('All topics')
->setGroup('navigation')
->setAction('jump_to', ['path' => route('categories.index')])
->setIcon('tag'),
SpotlightResult::make()
->setTitle('Feed')
->setGroup('follow-me')
->setAction('jump_to', ['path' => url('/feed')])
->setIcon('rss'),
SpotlightResult::make()
->setTitle('Follow me on X (formerly Twitter)')
->setGroup('follow-me')
->setAction('jump_to', ['path' => 'https://x.com/benjamincrozat'])
->setIcon('x'),
]);
})
);
});
}
public function boot() : void
{
Debugbar::addCollector($this->app->make(JobsCollector::class));
Model::unguard();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment