Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sphinx Laravel Package

hans-thomas/sphinx

View on GitHub
Deep Wiki
Context7

+++ date = "2023-06-26" draft = false weight = 9 description = "Installation guidance to install and setup Sphinx." title = "Installation" bref= "To install Sphinx, follow the below steps" toc = false +++

{{< rawhtml >}}

codecov GitHub Workflow Status GitHub top language GitHub release (latest by date) StyleCi

Install the package via composer

composer require hans-thomas/sphinx

Then, publish config file

php artisan vendor:publish --tag sphinx-config

Setting up

Model

First, use Hans\Sphinx\Traits\SphinxTrait trait on your model and then implement the abstract methods. Next, inside your model, make sure to call the hooks method in your booted method.

use SphinxTrait, SphinxTrait {
    SphinxTrait::hooks as private sphinxHooks;
}

protected static function booted() {
    self::sphinxHooks();
}

Auth configuration

First of all, define the provider.

'providers' => [
    // ...
    'sphinxUsers' => [
        'driver' => 'sphinx',
        'model'  => App\Models\User::class,
    ],
    // ...
],

Then, add your guard.

'guards' => [
    // ...
    'jwt' => [
        'driver'   => 'sphinxJwt',
        'provider' => 'sphinxUsers',
    ],
    // ...
],

And finally, you can set the jwt guard as default.

'defaults' => [
    // ...
    'guard'     => 'jwt',
    // ...
],

All sets.

Role model

Sphinx expects the role model of your project, contains requested method on Hans\Sphinx\Models\Contracts\RoleMethods interface class. So, you should implement this contract and for your convenient, there is the Hans\Sphinx\Models\Traits\RoleMethods trait class that contains all the methods that you must implement.

use Hans\Sphinx\Models\Contracts\RoleMethods as RoleContract;
use Hans\Sphinx\Models\Traits\RoleMethods;
use Spatie\Permission\Models\Role;

class RoleDelegate extends Role implements RoleContract {
use RoleMethods;

// ...
}

In addition, your role model should have a version column.

$table->unsignedInteger('version')->default(1);

If your using Spatie/laravel-permission package, you can use this migration class.

<?php

    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;

    return new class extends Migration {
        /**
         * Run the migrations.
         */
        public function up(): void
        {
            Schema::table(
                $tableName = config('permission.table_names.roles'),
                function (Blueprint $table) use ($tableName) {
                    if (!Schema::hasColumn($tableName, 'version')) {
                        $table->unsignedInteger('version')->default(1);
                    }
                }
            );
        }

        /**
         * Reverse the migrations.
         */
        public function down(): void
        {
            Schema::table(
                $tableName = config('permission.table_names.roles'),
                function (Blueprint $table) use ($tableName) {
                    if (Schema::hasColumn($tableName, 'version')) {
                        $table->dropColumn('version');
                    }
                }
            );
        }
    };

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky