Skip to content

Instantly share code, notes, and snippets.

@SketchBookkeeper
Last active March 8, 2019 15:50
Show Gist options
  • Save SketchBookkeeper/dc9744b855b88f9a8e965d260c5d70d2 to your computer and use it in GitHub Desktop.
Save SketchBookkeeper/dc9744b855b88f9a8e965d260c5d70d2 to your computer and use it in GitHub Desktop.
I tried going off both these guides but they did not work. Still good resources though. https://www.youtube.com/watch?v=AomK1eYAq78&list=PLUBR53Dw-Ef-X-_A1KLy41r2QArCBy4rM&index=23 https://vimeo.com/108040919

Extending the User Plugin

1 | Make a plugin php artisan create:plugin PaulAllen.profile

2 | In the udates folder, edit the database migration file. In this example it's create_profiles_table.php. We'll use this to add a column to the users table. I'm keeping this simple but in production you may want to make sure the users table actually exists. Here we are just adding a "bio" column.

<?php namespace PaulAllen\Profile\Updates;

use Schema;
use October\Rain\Database\Schema\Blueprint;
use October\Rain\Database\Updates\Migration;

class CreateProfilesTable extends Migration
{
    public function up()
    {
        Schema::table('users', function(Blueprint $table) {
            $table->text('bio')->nullable();
        });
    }

    public function down()
    {
        Schema::table('users', function(Blueprint $table) {
            $table->dropColumn('bio');
        });
    }
}

3 | Add the fields we want to the user controller. It's important to use RainLab\User\Controllers\Users in our Plugin.php in the newly created plugin.

We can add fields and tabs by using the extendFormFields method from the user controller. We'll add that to our boot method.

<?php namespace PaulAllen\Profile;

use System\Classes\PluginBase;
use RainLab\User\Controllers\Users as UsersController;

class Plugin extends PluginBase
{
    public function registerComponents()
    {
    }

    public function registerSettings()
    {
    }

    public function boot()
    {
        UsersController::extendFormFields(function($form, $model, $context){
            $form->addTabFields([
                'bio' => [
                    'label' => 'Bio',
                    'tab'   => 'Profile',
                    'type'  => 'textarea'
                ]
            ]);
        });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment