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

    Luís Novais

    07/15/2021, 9:13 PM
    I can use checkbox in settings section ?
  • i

    ifox

    07/15/2021, 9:15 PM
    You should be able to since 2.0.2 https://github.com/area17/twill/commit/d62d303fba5e3ea0e6bcd8e838933bdab0c270cc
  • i

    ifox

    07/15/2021, 9:18 PM
    like I've said in the past the settings section was initially made for key-value pairs and is being used much more than intended. We've added support for a couple more fields but ultimately the feature needs to be refactored to behave like a regular twill module so that any field would be supported.
  • i

    ifox

    07/15/2021, 9:18 PM
    are you seeing this error by just adding a simple checkbox field to a settings page, checking it and saving?
  • l

    Luís Novais

    07/15/2021, 9:19 PM
    no, I just see the error if I change de value of checkbox to true
  • i

    ifox

    07/15/2021, 9:20 PM
    how? by clicking on it? Or do you mean as default value? Can you share the formField snippet you use?
  • l

    Luís Novais

    07/15/2021, 9:21 PM
    When I change to True and want to update the settings give the error this is my file @extends('twill::layouts.settings', [ 'contentFieldsetLabel' => "Manutenção", 'additionalFieldsets' => [ ['fieldset' => 'seo', 'label' => 'SEO'], ['fieldset' => 'contacts', 'label' => 'Contactos'], ['fieldset' => 'links', 'label' => 'Links'], /* ['fieldset' => 'attributes2', 'label' => 'Attributes 2'], */ ] ]) @section('contentFields') @formField('checkbox', [ 'name' => 'maintenance', 'label' => 'Em manutenção' ]) @stop @section('fieldsets') @formFieldset(['id' => 'seo', 'title' => 'SEO']) @formField('input', [ 'name' => 'meta_title', 'label' => 'Título', ]) @formField('input', [ 'type' => 'textarea', 'name' => 'meta_description', 'label' => 'Descrição', ]) @endformFieldset @formFieldset(['id' => 'contacts', 'title' => 'Contactos']) @formField('input', [ 'name' => 'telefone', 'label' => 'Telefone/Telemovel', ]) @formField('input', [ 'name' => 'email', 'label' => 'Email', ]) @endformFieldset @formFieldset(['id' => 'links', 'title' => 'Links']) @formField('input', [ 'label' => 'Facebook', 'name' => 'facebook', ]) @formField('input', [ 'label' => 'Instagram', 'name' => 'instagram', ]) @formField('input', [ 'label' => 'Política privacidade', 'name' => 'privacy_policy', ]) @formField('input', [ 'label' => 'Termos e condições', 'name' => 'terms_conditions', ]) @formField('input', [ 'label' => 'Livro reclamações', 'name' => 'livro_reclamacoes', ]) @endformFieldset @stop
  • p

    pboivin

    07/15/2021, 9:25 PM
    I was able to replicate this on my end. Just added a checkbox to my settings page, default to
    false
    . Click it, then save. Got the same error.
  • p

    pboivin

    07/15/2021, 9:25 PM
    Interesting... @User a quick workaround would be to use a radio with yes/no.
  • l

    Luís Novais

    07/15/2021, 9:26 PM
    ok I will use that, no problem, thanks for your help guys
  • b

    Bibo

    07/17/2021, 11:46 AM
    Hi Everyone, I wish a great day for all of you, I wonder if I can get a help on a small point: I am building a news website in Arabic Languages ( RTL Direction ) The RTL Slugs are not being stored correctly in database, it is a little bit weird, here is an example: lets say a category slug in RTL ( Arabic ) is : تصنيف twill is storing it as : "tasnif" in database - it is converted to the same pronunciation using English characters, the problem is building the URL structure using this way will confuse the google bots. just want to know how to store the slug characters as it is in the database. please any ideas on how to deal with this, I will be so thankful.
  • i

    ifox

    07/17/2021, 11:51 AM
    Hi @Bibo, check this out: https://github.com/area17/twill/blob/17390bb6f5c5f14f92d97ec5a7881f5e5d382a45/src/Models/Behaviors/HasSlug.php#L127
  • i

    ifox

    07/17/2021, 11:51 AM
    config('twill.slug_utf8_languages')
  • i

    ifox

    07/17/2021, 11:52 AM
    if you add locale codes to this configuration, you should get what you are looking for.
  • b

    Bibo

    07/17/2021, 11:53 AM
    Thanks a lot I will check that immediately :))
  • b

    Bibo

    07/17/2021, 12:06 PM
    I've copied the updateOrNewSlug function to the model, then added the rtl language code as this config('twill.slug_utf8_languages', [ 'ar' ]) and it worked perfect. just one thing, the permalink line is not showing under the title, when I open the title / slug update modal, the slug shows empty, when I hit update it is fine, just not showing the slug value. I attached screenshot
  • i

    ifox

    07/17/2021, 12:27 PM
    you don't have to copy the code, just use the config in your
    config/twill.php
    file
  • b

    Bibo

    07/17/2021, 12:44 PM
    I did that, I added it to config/twill.php, please on update lets say I changed the slug, it does not save the new updated slug, and if I change the category name, it adds a new slug to the db but the new slug active = 0 In the screenshot, the same category_id just changed the title multiple times, every time it create a slug, but slug active is 0
  • b

    Bibo

    07/17/2021, 12:50 PM
    okay I found it, I forgot to change the app locale in config/app.php to 'ar', once I did that, now everything works fine. Thanks a lot for Help 🙂
  • a

    andrewsamuelhan

    07/18/2021, 5:26 AM
    Yes I’ve tried that. Some of my models have a relationship with slug. The foreign key name also predefined and I dont wanna change that “ex: slug_id”. So changing my getForeignKey() while having relationship with “slug” will cause an error. So I only made a modification “updateRepeater()” 🤣
  • a

    antonioribeiro

    07/19/2021, 4:40 PM
    I'm doing
    Copy code
    app(PostsRepository::class)->update($post->id, $data);
    And instead of just updating all fields on
    $data
    variable the repository is actually deleting everything (translations, fields, blocks...), because, probably, it needs
    $data
    to contain the whole model data (original + new). But to have that I would have to reconstruct what the CMS frontend send to the repository, which (I've been there) it's huge. Anyone did this differently here?
  • p

    pboivin

    07/19/2021, 5:09 PM
    @User Not directly related, but I reached a similar conclusion while investigating how the "duplicate" feature uses revisions under the hood. (The revisions data is generated on the frontend and is difficult to recreate manually on the backend.) Anyway, your problem makes me think — could you use revisions data to "hydrate" or "backfill" your $data before updating it?
  • i

    ifox

    07/19/2021, 5:15 PM
    @antonioribeiro what are you sending in
    $data
    ?
  • a

    antonioribeiro

    07/19/2021, 5:22 PM
    I was sending only some fields @User
  • a

    antonioribeiro

    07/19/2021, 5:24 PM
    Came up with a new update method to fix it:
    Copy code
    public function updateOnly($id, $updateFields)
    {
        DB::transaction(function () use ($id, $updateFields) {
            $object = $this->model->findOrFail($id);
    
            $fields = $this->prepareFieldsBeforeSave($object, $updateFields);
    
            $fields = $this->removeMissingFieldsFromUpdate(
                $fields,
                $updateFields,
            );
    
            $object->fill(Arr::except($fields, $this->getReservedFields()));
    
            $object->save();
        }, 3);
    }
    
    private function removeMissingFieldsFromUpdate(
        array $fields,
        $updateFields
    ): array {
        $locales = locales();
    
        $updateFields = collect($updateFields);
    
        foreach ($fields as $name => $field) {
            if ($updateFields->has($name)) {
                continue;
            }
    
            if ($locales->contains($name)) {
                $fields[$name] = $this->removeMissingFieldsFromUpdate(
                    $field,
                    $updateFields,
                );
    
                if (count($fields[$name]) === 0) {
                    unset($fields[$name]);
                }
    
                continue;
            }
    
            unset($fields[$name]);
        }
    
        return $fields;
    }
    This is very particular to my use case as it doesn't take in consideration blocks and other stuff, so we probably need a way better solution for this
  • v

    vianney

    07/19/2021, 5:41 PM
    Hi! What is the recommended Twill development environment setup if I wanted to run things like
    php artisan twill:dev
    I use Docker/Laradock at the moment and it's not agreeing with my setup and was wondering what you guys use: Homestead?, Valet?, Docker?, etc.
  • p

    pboivin

    07/19/2021, 6:02 PM
    Hey @User, I use Homestead for pretty much everything. I've heard a lot of good things about Valet on macOS (and Linux). Never used Docker for Twill development specifically, but it seems to trip people up occasionally...
  • v

    vianney

    07/19/2021, 6:04 PM
    yup! sounds good and thanks for the response:: gonna have to use Homestead as Docker is just another beast
  • p

    pboivin

    07/19/2021, 6:05 PM
    Out of curiosity, have you tried Sail? (It's the Docker kit from Laravel.)
  • v

    vianney

    07/19/2021, 6:08 PM
    Nope: I used Laradock
1...646566...484Latest