https://twill.io logo
Join Discord
Powered by
# ❓questions
  • k

    Kormi

    05/31/2022, 12:17 PM
    and how can I use directly Model User instead of profile ?
  • k

    kalle

    05/31/2022, 12:21 PM
    Twill uses default models with mixing of behaviour traits. You can implement own Repository and pass User Model as working one. Also you will need to create Controller and other needed things.
  • i

    ifox

    05/31/2022, 12:21 PM
    yes but Twill will try to do things with that model and if it doesn't extend the Twill model that won't work
  • k

    kalle

    05/31/2022, 12:22 PM
    He should be able to pass User as working Model?
  • i

    ifox

    05/31/2022, 12:23 PM
    sorry edited my message above while responding to you by mistake
  • i

    ifox

    05/31/2022, 12:23 PM
    that's why we add a dedicated model in the guide, so you don't have to extend Twill on the frontend User model
  • i

    ifox

    05/31/2022, 12:24 PM
    but it's still possible, just not necessarily recommended
  • k

    kalle

    05/31/2022, 12:33 PM
    Aha I got your point, thats true.
  • k

    Kormi

    05/31/2022, 12:36 PM
    ok i'm using profile module
  • k

    Kormi

    05/31/2022, 12:37 PM
    but how can i put the user email inside indexcolumns?
    Copy code
    protected $indexColumns = [
            'first_name' => [
                'field' => 'first_name',
                'title' => 'Name',
                'sort' => true,
                'visible' => true,
            ],
            'last_name' => [
                'field' => 'last_name',
                'title' => 'Last Name',
                'sort' => true,
            ],
            'company' => [
                'field' => 'company',
                'title' => 'Company',
                'sort' => true,
            ],
            'phone' => [
                'field' => 'phone',
                'title' => 'Phone',
                'sort' => true,
            ],
            'email' => [
                'field' => 'user.email',
                'title' => 'E-mail',
                'sort' => true,
            ],
        ];
  • k

    Kormi

    05/31/2022, 12:37 PM
    in profile model i Have
    Copy code
    public function user()
        {
            return $this->belongsTo(User::class);
        }
  • h

    Harings Rob

    05/31/2022, 12:42 PM
    @Kormi I recently mentioned relations here: https://discord.com/channels/811936425858695198/980863444393799701
  • k

    Kormi

    05/31/2022, 1:00 PM
    and can I add a field from relationship to like titleColumnKey??
    protected $titleColumnKey = 'first_name';
  • k

    Kormi

    05/31/2022, 1:01 PM
    and is there a way to do something when an admin publish a user? I would like to send an email...
  • h

    Harings Rob

    05/31/2022, 1:09 PM
    no you do not have to change the titleColumnKey
  • k

    kalle

    05/31/2022, 1:24 PM
    https://twill.io/docs/guides/manage_frontend_user_profiles_from_twill.html#complete-user-management-from-the-cms
  • k

    kalle

    05/31/2022, 1:25 PM
    You have to make ProfileRepository which have methods like
    afterSave
    or
    prepareFieldsBeforeSave
    which you override and check if
    publish
    is 1/true from the form. And in that method make a mail logic.
  • k

    Kormi

    05/31/2022, 1:26 PM
    i add this in my repository
  • k

    Kormi

    05/31/2022, 1:26 PM
    Copy code
    public function afterSave($object, $fields)
        {
            parent::afterSave($object, $fields);
            var_dump($fields);die;
        }
  • k

    Kormi

    05/31/2022, 1:27 PM
    Admin can only publish or unpublish a user
  • k

    Kormi

    05/31/2022, 1:27 PM
    when i click PUBLISH an ajax call is launched
  • k

    Kormi

    05/31/2022, 1:28 PM
    but die() does not appear
  • k

    kalle

    05/31/2022, 1:28 PM
    You need to finish the cycle.
    Copy code
    php
        public function afterSave($object, $fields)
        {
            dd($fields);
            return parent::afterSave($object, $fields);  
        }
  • k

    kalle

    05/31/2022, 1:29 PM
    Or Im not sure but response could be resolved before this afterSave is invoked.
  • k

    kalle

    05/31/2022, 1:29 PM
    prepareFieldsBeforeSave
    is invoked before insert.
  • k

    Kormi

    05/31/2022, 1:30 PM
    i'm not sure it works
  • k

    kalle

    05/31/2022, 1:31 PM
    Copy code
    php
        public function prepareFieldsBeforeSave($object, $fields)
        {
            dd($fields);
            return parent::prepareFieldsBeforeSave($object, $fields);  
        }
  • k

    Kormi

    05/31/2022, 1:31 PM
    i only click this publish
  • k

    kalle

    05/31/2022, 1:31 PM
    Which part?
  • k

    Kormi

    05/31/2022, 1:32 PM
    maybe this call doesn't invoke those functions?
1...334335336...484Latest