question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Developers should be able to add custom buttons. Proposed syntax:

$this->crud->addButton('button_name', 'model_function_name'); 
// by default this will place the button before edit and delete
// ex: $this->crud->addButton('send_email', 'getSendEmailButton');

// other methods:
$this->crud->removeButton('send_email');
$this->crud->setButtonsOrder(['edit', 'send_email', 'delete']);

This way, I think, we’ll leave a lot of space for customization. On your model, you could do something like:

public function getSendEmailButton() {
    return "<a class='btn btn-warning' href='some_link'><i class='fa fa-envelope'> Send email</a>"; 
}

and you can have your checks or complex logic there. Ex:

  • show the button to some users and others not.
  • show the button for some entries and others not.
  • show different url depending on some model attribute.
  • etc.

What I don’t like about this is that it does imply you’ll be writing some HTML in the model, which is a bit ugly… What do you think? Any better solutions?

Note: I also see the need for custom bulk buttons in the future. But that’s another topic.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
axyrcommented, Jun 15, 2016

Please see these examples how I use your crud right now (work in progress):

https://gist.github.com/axyr/4328d6dba6462d6639347e226182d218 https://gist.github.com/axyr/336934ff114cb943e26bdf9823affd97 https://gist.github.com/axyr/2bf47beaa6af77d7fd48836a694372d2

By applying namingconventions, I only have to create MyModelController extends ModelAdminController to get a list and form view for MyModel.

1reaction
axyrcommented, Jun 15, 2016

https://laravel-backpack.readme.io/docs/crud-fields This will become an array hell:

[   // PageOrLink
    'name' => 'type',
    'label' => "Type",
    'type' => 'page_or_link',
    'page_model' => '\Backpack\PageManager\app\Models\Page'
],
[  // Select
   'label' => "Category",
   'type' => 'select',
   'name' => 'category_id', // the db column for the foreign key
   'entity' => 'category', // the method that defines the relationship in your Model
   'attribute' => 'name', // foreign key attribute that is shown to user
   'model' => "App\Models\Tag" // foreign key model
],
[       // SelectMultiple = n-n relationship (with pivot table)
    'label' => "Tags",
    'type' => 'select_multiple',
    'name' => 'tags', // the method that defines the relationship in your Model
    'entity' => 'tags', // the method that defines the relationship in your Model
    'attribute' => 'name', // foreign key attribute that is shown to user
    'model' => "App\Models\Tag", // foreign key model
    'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
]

No IDE autocompletion possible, so you always have to go to the docs to see the options possible for maybe tens (>100?) of different form fields.

When using objects, you can apply sensible defaults for, name, attribute, label based on the field name, with auto translations like label(‘MyModel.field_name’, ‘default label’);

Also the model can be guessed for a FormField user_id that it should find the hasOne User();

So you can do :

new DropdownField('user_id', /*optional name*/, /* optional collection or array of items*/);

And by default it will will provide a map of [‘id’, getTilte()] or something.

That will help beginners a lot, by having real usable sensible defaults by just boilerplating their models and controllers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promotional Custom Buttons by: Everyone Loves Buttons®
Welcome to CustomButtons.com—your premier source for all your custom buttons, magnetic buttons and more. From 1 to 1,000,000+, you're at the right place—we ......
Read more >
Order Custom Buttons - 19 Button Sizes: Round, Square ...
Order custom buttons for as low as $0.19 each! Easy to personalize and affordably priced with a minimum order of just one custom...
Read more >
Custom buttons | Free shipping - Sticker Mule
Create custom buttons in full color. High quality steel with durable pin-backs. Get free proofs, free worldwide shipping, 4 day turnaround & 24/7...
Read more >
Fast Filmmaking Settings For The Sony FX30 Part 2 - YouTube
Download my FX30 Settings Preset: https://get.whoismatt.com/fx30presetHere is how to setup the custom buttons, function menu, mode dial, ...
Read more >
Custom Buttons - Buy Customizable Buttons Online
Design custom buttons using our online button designer, or upload print-ready graphics! We will proof, print, and press your one-of-a-kind custom buttons!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found