I've been creating a lot of custom columns that are identical to the standard ones provided with Backpack except that I'm making the contents links elsewhere in the project.
Was thinking it would be a nice addition to have an optional 'href' => '/some/link' and 'href_text' => 'Text for link' parameters on all columns with a corresponding @if() in the blade file to easily add links to any column (or at least the ones that make sense, probably wouldn't with a column that outputs an array/list)
Definitely would add it too:
There may be some others that make sense too that I missed
Hello there! Thanks for opening your first issue on this repo!
Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps _a lot_ in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.
Backpack communication mediums:
backpack-for-laravel tag;Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome _awesome_ community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.
Thank you!
--
Justin Case
The Backpack Robot
Hmm…. I believe image and email already have anchors.
But I think it’s a _great_ idea for ALL columns to have _the posibility_ to have anchors, yes. Some would have a sensible default link, because it makes sense, some will not. And that should keep the backwards-compatibility.
I think that’s a great idea. My thoughts on it:
href, but it might also be useful to specify the target; you might want some links to open in the same page, others in another tab; so it would be useful to also be able to specify that; I don’t know what else it would make sense to specify on this anchor element, but since we already have two attributes, it would probably make sense to just allow the developer to specify any attribute his heart desires; so maybe an anchor attribute, which is an array of href, target and whatever else the developer wants would allow the most customization; this would also open up the possibility of styling the contents of a cell depending on its content - if you can specify a class or style attribute on the anchor; so you can maybe have green labels for good stuff using class=‘label label-success’, red labels for bad stuff, things like that; href at least, the value will most likely need to be a closure, so that the developer specifies how to construct the URL (since it should be different for each entry); so for each anchor attribute, we should probably allow two types of content: text (will just output it) and closure (will run it, then show the output);So I think this feature could look something like this:
// custom anchor around an image
$this->crud->addColumn([
'name' => ‘image',
'label' => ‘Image',
'type' => ‘image’,
'anchor' => [
'href' => function($entry, $column, $crud) {
return asset('user/images/'.$entry->hash.'png');
},
'target' => '_blank',
'class' => 'img img-rounded',
],
]);
// custom anchor around a text, that turns it into a label
$this->crud->addColumn([
'name' => ’status',
'label' => ’Status',
'type' => ’text’,
'anchor' => [
'href' => '',
‘class' => function($entry, $column, $crud) {
if ($entry->status == ‘good’) { return ‘label label-success’; }
if ($entry->status == ‘bad’) { return ‘label label-danger’; }
return ‘label label-default’;
},
],
]);
// custom anchor around a relationship, that links to that entry
$this->crud->addColumn([
// 1-n relationship
'label' => "Parent", // Table column heading
'type' => "select",
'name' => 'parent_id', // the column that contains the ID of that connected entity;
'entity' => 'parent', // the method that defines the relationship in your Model
'attribute' => "name", // foreign key attribute that is shown to user
'anchor' => [
'href' => function($entry, $column, $crud) {
if (!entry) { return ‘'; }
return backpack_url(‘users/'.$entry->id);
},
],
]);
href_text would be useful in any way… In my opinion, the href text should be the actual column content, shouldn’t it? And specifying it from the controller would just make it _the same text_ for all columns, which would defeat the purpose of the column. Please correct me if I’m wrong.What do you think @redf150flames ? Anybody else? Let’s see if we can make this as good as possible before implementation.
@Laravel-Backpack/veterans - thoughts?
@tabacitu glad to hear you agree with the idea! Sorry it took a while to get back, been a busy week.
target and class, I left it off in my original trying to keep things as simple as possible, so maybe it could be optional as well?href_text for my custom column when I initially made this feature request. but ended up removing it, so yes, that is unnecessary. I think this is a must have feature. I find myself creating columns from model functions to return anchors to the linked entitites. Thanks.
Did you add this feature or not yet? I searched the docs but couldn't find anything related.
I want to link to another model or discussion->user(), and there are many other use cases I will need this feature for.
Should I do it manually?
@MostafaAttia - no, it's not implemented yet. Best to go ahead and create a custom column type for your use case.
Working example of a column showing "x entries" with link here.
$this->crud->addColumn([
'type' => 'relationship_count',
'name' => 'snippets',
'label' => 'Snippets',
'suffix' => ' entries',
'link' => function($entry) {
return backpack_url('creator/'.$entry->id.'/snippet');
}
]);
Maybe someone will find it useful until we push anchors/links to all columns.
Going to close this, please keep the discussion on PR #2448
Thanks @redf150flames for bring this to our attention.
Best,
Pedro
Most helpful comment
Hmm…. I believe
imageandemailalready have anchors.But I think it’s a _great_ idea for ALL columns to have _the posibility_ to have anchors, yes. Some would have a sensible default link, because it makes sense, some will not. And that should keep the backwards-compatibility.
I think that’s a great idea. My thoughts on it:
href, but it might also be useful to specify thetarget; you might want some links to open in the same page, others in another tab; so it would be useful to also be able to specify that; I don’t know what else it would make sense to specify on this anchor element, but since we already have two attributes, it would probably make sense to just allow the developer to specify any attribute his heart desires; so maybe ananchorattribute, which is an array ofhref,targetand whatever else the developer wants would allow the most customization; this would also open up the possibility of styling the contents of a cell depending on its content - if you can specify aclassorstyleattribute on the anchor; so you can maybe have green labels for good stuff usingclass=‘label label-success’, red labels for bad stuff, things like that;hrefat least, the value will most likely need to be a closure, so that the developer specifies how to construct the URL (since it should be different for each entry); so for each anchor attribute, we should probably allow two types of content:text(will just output it) andclosure(will run it, then show the output);So I think this feature could look something like this:
href_textwould be useful in any way… In my opinion, the href text should be the actual column content, shouldn’t it? And specifying it from the controller would just make it _the same text_ for all columns, which would defeat the purpose of the column. Please correct me if I’m wrong.What do you think @redf150flames ? Anybody else? Let’s see if we can make this as good as possible before implementation.