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

    user

    06/03/2021, 10:19 PM
    Thank you very much 🙂
  • u

    user

    06/03/2021, 10:24 PM
    One more question, how can I pass data from controllers to the repeaters? I mean, assume that I have a "select" input in the repeater template and when I try to send the options from controller I get "Undefined variable" error.
  • i

    ifox

    06/03/2021, 10:49 PM
    the config array is not necessary anymore thanks to the annotation @pablobarrios shared, but it was actually at the wrong location in your file, otherwise it should have worked. It should have been under
    twill.block_editor.repeaters
    not
    twill.repeaters
    , you can just remove it now though
  • i

    ifox

    06/03/2021, 10:50 PM
    you'd need to either get what you need from the repeater file itself or use a laravel view composer, because it could be many controllers that would serve this repeater, even though it might be just in one form in your case
  • u

    user

    06/03/2021, 11:13 PM
    Thanks for the explanation @User. For my scenario, I solved the data transfer like below:
    Copy code
    @php
    $cinemas = app()->make(\App\Repositories\CinemaRepository::class)->listAll('name');
    @endphp
    
    @formField('select', [
        'name' => 'cinema',
        'label' => 'Cinema',
        'options' => $cinemas
    ])
    
    @formField('date_picker', [
        'name' => 'published_at',
        'label' => 'Time'
    ])
    
    @twillRepeaterTitle('Seance')
    @twillRepeaterTrigger('Add Seance')
    However, I could save the picked cinema with the related model(checked from db), saw the picked id from the dropdown in the "getFormFields" but the picked cinema does not seem selected on the "cinemas" dropdown. Do you have any guess?
  • u

    user

    06/03/2021, 11:16 PM
    Btw I used a lot the select component on the other templates with relations and it worked very well. It is hard to use in the repeaters or I am still missing some basic stuff about that.
  • i

    ifox

    06/03/2021, 11:30 PM
    How do you save/retrieve the repeater in the repository?
  • i

    ifox

    06/03/2021, 11:31 PM
    do you have a
    cinema
    column on a Seance model?
  • i

    ifox

    06/03/2021, 11:32 PM
    ok just re-read and you can see it in db
  • i

    ifox

    06/03/2021, 11:32 PM
    can you share the output of getFormFields? specifically the repeater data
  • u

    user

    06/04/2021, 5:08 AM
    Hi, has anybody experienced issues displaying cropped photos on the frontend?
    Copy code
    html
    
    <div>
      {!! $project->image('cover_image', 'desktop') !!}
    </div>
    This shows me the full image even though I have cropped it
  • u

    user

    06/04/2021, 6:05 AM
    Dear @User here is my seance model:
    Copy code
    class Seance extends Model
    {
        protected $fillable = [
            'published',
            'movie_id',
            'cinema_id',
            'published_at',
            'booking_url',
            'type'
        ];
    
        public function movie()
        {
            return $this->belongsTo(Movie::class);
        }
    
        public function cinema()
        {
            return $this->belongsTo(Cinema::class);
        }
    
    }
  • u

    user

    06/04/2021, 6:05 AM
    and here is my SeanceRepository:
    Copy code
    class SeanceRepository extends ModuleRepository
    {
    
        public function __construct(Seance $model)
        {
            $this->model = $model;
        }
    
        public function getFormFields($object)
        {
            $fields = parent::getFormFields($object);
    
            return $fields;
        }
    
        public function afterSave($object, $fields)
        {
            /** @var Seance $object */
            $object->cinema_id = $fields['cinema'];
            $object->save();
            parent::afterSave($object, $fields);
        }
    }
  • r

    Rayderxx

    06/04/2021, 8:26 AM
    you could use the browser formField for the "cinema" relationship
  • i

    ifox

    06/04/2021, 8:28 AM
    if you use
    cinema_id
    as the name of the select field, you shouldn't need that code in the repo
  • u

    user

    06/04/2021, 9:52 AM
    Actually there is a ManyToOne relation between the seance and the cinema. Because of that when I want to try the "browser" field instead of the classic dropdown with using "getFormFieldsForBrowser" method inside the SeanceRepository, I get this error:
  • r

    Rayderxx

    06/04/2021, 9:56 AM
    @User browser with BelongsTo only work with twill 2.3.0
  • u

    user

    06/04/2021, 9:56 AM
    hm, let me update and try, thanks a lot.
  • r

    Rayderxx

    06/04/2021, 9:57 AM
    https://github.com/area17/twill/pull/913
  • u

    user

    06/04/2021, 10:22 AM
    Thanks @User I updated the twill, and changed the repo in the way of described in that pull request you sent. However, it seems the repeater is broken right now:
  • i

    ifox

    06/04/2021, 10:52 AM
    @User did you run
    php artisan twill:update
    ?
  • u

    user

    06/04/2021, 10:55 AM
    @User I hadn't, ran now. I think I am getting a progress 🙂
  • u

    user

    06/04/2021, 10:55 AM
    It seems the client side knows that there is a "cinema" but couldn't display the name.
  • u

    user

    06/04/2021, 10:55 AM
    here is my last repeater template:
    Copy code
    @formField('browser', [
        'moduleName' => 'cinemas',
        'name' => 'cinema',
        'label' => 'Cinema',
        'max' => 1,
    ])
    
    @formField('date_picker', [
        'name' => 'published_at',
        'label' => 'Time'
    ])
    
    @twillRepeaterTitle('Seance')
    @twillRepeaterTrigger('Add Seance')
  • u

    user

    06/04/2021, 10:56 AM
    btw cinema model has no "title", only "name" for it. Can it be the reason?
  • u

    user

    06/04/2021, 10:58 AM
    And it seems we have the data in the db also:
  • r

    Rayderxx

    06/04/2021, 11:07 AM
    @User yeah maybe try this ? 😄 https://github.com/area17/twill/pull/942
  • r

    Rayderxx

    06/04/2021, 11:12 AM
    https://github.com/area17/twill/blob/72ef99729f2b44fc9613cbd110d002a3937e2d18/src/Repositories/Behaviors/HandleBrowsers.php#L25
  • p

    pablobarrios

    06/04/2021, 11:14 AM
    Hey @User , which version of Twill are you running? Also, are you using Imgix or Glide?
  • u

    user

    06/04/2021, 11:24 AM
    Hey @User, it worked with the code below:
    Copy code
    <?php
    
    namespace App\Repositories;
    
    
    use A17\Twill\Repositories\ModuleRepository;
    use App\Models\Seance;
    
    class SeanceRepository extends ModuleRepository
    {
    
        public function __construct(Seance $model)
        {
            $this->model = $model;
        }
    
        protected $browsers = [
            'cinema' => [
                'titleKey' => 'name'
            ]
        ];
    
    
    }
    Many thanks guys @User @User @User I wish I can get some beer for you from here 🙂
1...202122...484Latest