Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Confusion over documentation #31

Open
ziming opened this issue Mar 21, 2019 · 2 comments
Open

Confusion over documentation #31

ziming opened this issue Mar 21, 2019 · 2 comments

Comments

@ziming
Copy link

ziming commented Mar 21, 2019

Detailed description

Hi! wanted to ask some questions as I am confused over the documentation given the use of a generic word like 'entity'

Imagine I have 2 models. SoftDrink and User with the following rules:

  • 1 DrinkingUser hasMany SoftDrink.
  • 1 SoftDrink belongsTo 1 DrinkingUser

My questions are below:

  1. Do I have to add InstantFields trait to both SoftDrinkCrudController and DrinkingUserCrudController?

  2. Do I have to do this to both DrinkingUser and SoftDrink backpack routes?

CRUD::resource('soft-drink', 'SoftDrinkCrudController')->with(function () {
        Route::any('soft-drink/ajax/{mode?}', 'SoftDrinkCrudController@handleAjaxRequest');
    });

CRUD::resource('drinking-user', 'DrinkingUserCrudController')->with(function () {
        Route::any('drinking-user/ajax/{mode?}', 'DrinkingUserCrudController@handleAjaxRequest');
    });
  1. Am I correct to say that $this->setAjaxEntity('soft-drink'); is added to setup() method of SoftDrinkCrudController only?

  2. I'm going to add this field definition to DrinkingUserCrudController but it doesn't seem to work (after all users table has no soft_drink_id. Is UserCrudController the right place? Or is this supposed to be added to SoftDrinkCrudController to allow create/edit user to show the field to add soft drinks?

[
    'name'                 => 'soft_drink_id',
    'type'                 => 'select2_from_ajax',
    'label'                => 'Soft Drink',
    'view_namespace'       => 'webfactor::fields',
    'model'                => SoftDrink::class,
    'entity'               => 'soft-drink',
    'attribute'            => 'name',
    'placeholder'          => 'Choose',
    'minimum_input_length' => 0,
    'on_the_fly'           => [
        'entity'        => 'soft-drink', // e. g. user, contact, company etc...
    ],
],
  1. For instant create button in list view, May I assume it is this?
Inside DrinkingUserCrudController

$this->addInstantCreateButtonToList(
        'soft-drink', // foreign entity. Should it be soft-drink or softDrinks?
        'add soft drink', // content of the button
        'soft-drink-id', // the name of the ID of the current entity will be 
    );

Thank you!

@tswonke
Copy link
Member

tswonke commented Mar 21, 2019

Hi @ziming

I know this is a bit confusing, but there are some technical limitations in Laravel Backpack so I had to trick a bit. That's the reason why I recommend using the trait and routes for all (involved) CrudControllers.

  1. yes
  2. yes
  3. yes - should be enough in your case but:
  4. this won't work for you currently*
  5. yes, should be right

*The kind of field type you need is not available yet:

You need a corresponding field type to the function of the button (5.) in the crud list. I definitively see the requirement for such a field type and hope we can provide it soon, because we also need it.

@swayoleg
Copy link

swayoleg commented Aug 7, 2019

The module is awesome but documentation is .... unclear

Can you please add simple example with something obvious like Country + City?
Where to use trait etc.

Thanks

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants