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

    Nechalon

    03/10/2023, 12:17 PM
    Yes, I kinda what im looking for:D
  • i

    ifox

    03/10/2023, 12:17 PM
    since there is no way to pass a value to a field from blade, it needs to be returned in the form fields data or from a model accessor
  • n

    Nechalon

    03/10/2023, 12:18 PM
    what can I do with
    getFormFields
    ?
  • n

    Nechalon

    03/10/2023, 12:20 PM
    add a function in the repo?
    Copy code
    public function getFormFields($object)
        {
            $fields = parent::getFormFields($object);
            $fields = $this->getFormFieldsForRepeater($object, $fields, 'members', 'TeamMember', 'team-member');
            return $fields;
        }
  • i

    ifox

    03/10/2023, 12:22 PM
    Copy code
    php
    public function getFormFields($object) {
        $fields = parent::getFormFields($object);
    
        $fields['user_name'] = User::find($object->user_id)?->name;
    
        return $fields
    }
    In the form:
    Copy code
    @formField('input', [
        'name' => 'user_name',
        'label' => 'User name',
        'disabled' => true
    ])
  • n

    Nechalon

    03/10/2023, 12:24 PM
    wow, that worked instantly, thanks a lot 😁
  • k

    kalle

    03/10/2023, 12:25 PM
    Or alternative to this, you can append property to the model and resolve it directly in the model. Twill will handle it automaticly by name
    user_name
    which is appended to the model.
  • n

    Nechalon

    03/10/2023, 1:53 PM
    How can I add columns to sort? Here->
  • i

    ifox

    03/10/2023, 1:54 PM
    Using
    $indexColums
    in your module controller
  • i

    ifox

    03/10/2023, 1:54 PM
    and accessors on your model
  • j

    jefsev

    03/10/2023, 1:54 PM
    Hi is there a way in twill 3 to add my own custom statuses and change this in the CMS to something that is more usefull for orders.
  • i

    ifox

    03/10/2023, 1:54 PM
    yup! One sec
  • n

    Nechalon

    03/10/2023, 1:54 PM
    Thats where I added these, but they dont show on the table row itself
  • i

    ifox

    03/10/2023, 1:56 PM
    Override
    getSubmitOptions
    in your module controller
  • i

    ifox

    03/10/2023, 1:57 PM
    can you share that declaration?
  • n

    Nechalon

    03/10/2023, 2:07 PM
    of course
    Copy code
    protected $indexColumns = [
            'title' => [ 
                'title' => 'Title',
                'field' => 'title',
            ],
            'User Name' => [
                'title' => 'User Name',
                'field' => 'user_name',
                'sort' => true,
            ],
            'User Email' => [
                'title' => 'User Email',
                'field' => 'user_email',
                'sort' => true,
            ],
        ];
  • i

    ifox

    03/10/2023, 2:08 PM
    Did you define
    getUserNameAttribute()
    and
    getUserEmailAttribute()
    in the model behind this controller?
  • i

    ifox

    03/10/2023, 2:09 PM
    there's no way for twill to understand that it's supposed to find the user from the id in your table without those accessors
  • n

    Nechalon

    03/10/2023, 2:10 PM
    not yet, thats why im asking because I had no idea what i supposed to do
  • i

    ifox

    03/10/2023, 2:11 PM
    also I'm afraid sort won't work by default with such case. You will need to implement a custom
    order
    method in the repository to order by a custom key. Without that the only thing it would know how to sort on would be the id column, since that's the only on in your model
  • n

    Nechalon

    03/10/2023, 2:11 PM
    thats no big deal if I can fix it just like before (adding a function in the repo)
  • n

    Nechalon

    03/10/2023, 2:11 PM
    (somehow)
  • i

    ifox

    03/10/2023, 2:13 PM
    Copy code
    php
    public function getUserNameAttribute() 
    {
        return User::find($this->user_id)?->name;
    }
  • i

    ifox

    03/10/2023, 2:14 PM
    Copy code
    php
    public function getUserEmailAttribute() 
    {
        return User::find($this->user_id)?->email;
    }
  • i

    ifox

    03/10/2023, 2:14 PM
    I would create a third function to avoid repeating yourself
  • i

    ifox

    03/10/2023, 2:15 PM
    and yes the order function is to override in the repository
  • i

    ifox

    03/10/2023, 2:16 PM
    you will need to add the
    sortKey
    parameter to your indexColumns columns, and use that in the order function to order by it
  • i

    ifox

    03/10/2023, 2:16 PM
    Question for you though, why don't you have a user() relationship in your model?
  • i

    ifox

    03/10/2023, 2:16 PM
    since you're storing a foreign key id for it
  • n

    Nechalon

    03/10/2023, 2:18 PM
    I forgot it, I started doing the forms and got sidetracked
1...476477478...484Latest