Edit User Profile: Frontend (Extend Users Module)
Created 6 years ago by finnito

Hi all!

I'm trying to extend the Users Module to allow frontend editing of user profiles. I am doing this in a module called Members Module (finnito.module.members).

In my service provider I have defined a route:

protected $routes = [
        'profile'                              => [
            'as'   => 'finnito.module.members::profile',
            'uses' => 'Finnito\MembersModule\Http\Controller\MembersController@profile',
        ],
    ];

This controller simply auths the user and attempts to render the form: MembersController.php

<?php namespace Finnito\MembersModule\Http\Controller;

use Anomaly\Streams\Platform\Http\Controller\PublicController;
use Finnito\MembersModule\User\Form\MembersFormBuilder;
use Illuminate\Contracts\Auth\Guard;

class MembersController extends PublicController {
    public function profile(Guard $auth, MembersFormBuilder $form) {
        if(!$user = $auth->user()) {
            abort(404);
        }
        return $form->render($user->id);
    }
}

The problem is that it renders the form defined below, but no existing values are populated into the form. src/User/Form/MembersFormBuilder.php:

<?php namespace Finnito\MembersModule\User\Form;

use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
use Anomaly\UsersModule\User\Form\UserFormBuilder;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;

class MembersFormBuilder extends FormBuilder {

    protected $model = UserFormBuilder::class;

    protected $fields = [
        'first_name' => [
            "type" => "anomaly.field_type.text",
            "placeholder" => "First Name",
        ],

        'email' => [
            "type" => "anomaly.field_type.text",
            "placeholder" => "Email",
        ],
    ];

    /**
     * The form actions.
     *
     * @var array|string
     */
    protected $actions = [
        "blue" => [
            "text" => "Update",
        ],
    ];
}

For example, my first_name is set to "Finn" but I get an empty input field when viewing the page.

Can someone help with how I should fix this? It would be much appreciated; I have been stuck for a few days now 🙍

Thanks,

Finn!

finnito  —  6 years ago Best Answer

I needed to use an AdminController instead of a PublicController.

pooria  —  5 years ago

@finnito I have the same problem but nothing works 🙍

finnito  —  5 years ago

Hey @pooria! Can you show me what you've got? I figured out that I needed to use an AdminController instead of a PublicController in the end and I've implemented this in a couple of modules now.