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'
]
]);
});
}
}