randm's avatar

How to create a new extension for Cartalyst Platform?

Hi, I installed Cartalyst Platform 4.0 and I am trying to play around with it so I can understand it since the is not a whole lots of lessons out there.

I simply copied the Access Extension located on \extensions\platform\access into and \extensions\crm\access and then I renamed it to "accounts" (i.e.\extensions\crm\accounts)

Then I changed all the name spaces to the new path.

But every time I open my app I get this error Class 'crm\Accounts\Providers\AccountsServiceProvider' not found

I don't know why am I getting this error I do have AccountsServiceProvider.php file with the AccountsServiceProvider class name located on \extensions\crm\accounts\Providers

I am not sure is it because I created another folder next to the platform? I am just trying to keep my extensions separate from the extensions that comes with the Platform.

What do I need to do to fix this issue?

Here is my AccountsServiucePrivider class

<?php
namespace crm\Accounts\Providers;

use Illuminate\Support\Facades;
use Platform\Access\Redirector;
use Platform\Access\UrlGenerator;
use Cartalyst\Support\ServiceProvider;

class AccountsServiceProvider extends ServiceProvider
{
    /**
     * {@inheritDoc}
     */
    public function boot()
    {
        // Load the filters
        require __DIR__.'/../filters.php';

        // Overrides the Sentinel models
        $this->overrideSentinelModels();
    }

    /**
     * {@inheritDoc}
     */
    public function register()
    {
        $this->prepareResources();

        $this->registerMiddleware();

        $this->setAdminUri();
    }

    /**
     * Prepare the package resources.
     *
     * @return void
     */
    protected function prepareResources()
    {
        $config = realpath(__DIR__.'/../../config/config.php');

        $this->mergeConfigFrom($config, 'crm-accounts');

        $this->publishes([
            $config => config_path('crm-accounts.php'),
        ], 'config');
    }

    /**
     * Registers the permissions middleware.
     *
     * @return void
     */
    protected function registerMiddleware()
    {
        $this->app['router']->middleware('permissions', 'Platform\Access\Middleware\Permissions');
    }

    /**
     * Sets the admin uri on the url generator.
     *
     * @return void
     */
    protected function setAdminUri()
    {
        $this->app['url']->setAdminUri(admin_uri());
    }

    /**
     * Overrides the Sentinel models.
     *
     * @return void
     */
    protected function overrideSentinelModels()
    {
        // Get the roles and users models
        $rolesModel = get_class($this->app['Platform\Roles\Models\Role']);
        $usersModel = get_class($this->app['Platform\Users\Models\User']);

        // Set our models within Sentinel
        $this->app['sentinel.roles']->setModel($rolesModel);
        $this->app['sentinel.users']->setModel($usersModel);
        $this->app['sentinel.persistence']->setUsersModel($usersModel);

        // Override the users model on the roles model
        $rolesModel::setUsersModel($usersModel);

        // Override the roles model on the users model
        $usersModel::setRolesModel($rolesModel);
    }
}
0 likes
3 replies
randm's avatar

@Turaylon Thank you for your help. I went through both link but still can't figure out how to add an extension.

Do I create everything from the control panel? will the control panel generate the files for me?

Where do I start and how to I get my first extension going?

Turaylon's avatar

@malhayek yes, from the control panel in the workbench section you should create a new extension. All the proper file and folders will be scaffolded for you. And when you create the extensions there are tools in the extension management section that let you scaffold all sort of things in a simple click.

Please or to participate in this conversation.