How to add another table column in searchable array in nova? - laravel

i am getting data from different different tables and i displayed all those in one section that section contains search button also, i want to add another resource field as a searchable item in nova ,i am trying to add based on the relation of the particular table but it's throwing an error undefined column, How to add please help..
public static $searchable=['id','name','account.type'];

Basically, the search by relationship is not possible through Nova.
A package well made for your needs is this one: LaravelNovaSearch
This package includes both relationship search but also has other useful features making the search much more comprehensive.
Another package, which I have not personally tested, but which seems to be useful for your needs: NovaSearchRelations
My advice is to use LaravelNovaSearch, more maintained and more complete.

Related

Laravel: A field that lookup another field from different table

I use Backpack for Laravel.
I know that to add a field, we can use:
CRUD::addField(['name'=>..])
But, I don't know how to add a field that lookup another field input from different table to show a lookup value.
Please look at the illustration below.
Thanks.
Edit:
I found a temporary solution to this, but not effective.
Reference: https://backpackforlaravel.com/docs/4.1/crud-how-to#add-a-select2-field-that-depends-on-another-field
With select2_from_ajax you still have to select the option (even its just one option left), meanwhile what I really want is its automatically select that one option.
It's depends on what you need to do. You can use relationship field and show a select with the list of user. If you really wanna do it like this. You can probably make an ajax request to show it. In that case you ll need to use a custom view for the edit or the create view.

How does beforeSaveAddressInformation plugin

I was looking at this post: Magento 2 Add a custom input field on chackout forrm and save it
I have tried the same way but I am not sure how this part came
$customField = $shippingAddressExtensionAttributes->getFiscalCode();
$shippingAddress->setFiscalCode($customField);
Where is this getFiscalCode?
It's a Custom AttributeCode.
the getFiscalCode() method is an accessor method that is used to identity fields such as the one that is created with the extension attribute fiscal_code mentioned in the example.
It is not just extension attributes, but all collection models in magento use the following camel casing structure where for example the column entity_id in database table, can be accessed via either $modelCollection->getEntityId() or $modelCollection->setEntityId($valueOfEntityId)
This is a good read to understand the idea Magento 2: CRUD Models for Database Access

Filtering instances not related to the current contact

I have a custom entity Stuff and it contains a lookup to Contact. I created a 1:N relation with the latter as primary and the former as related entity.
On the Contact's form I added a subgrid and I only wish to list the instances of Stuff that have the lookup pointing to the currently viewed Contact. However, when I choose Only Related Records, the custom entity isn't in the list (despite it being related via the 1:N relation).
So, I'm using All Record Types, instead, but that shows all the instances of Stuff and not, as I wish, only those that are related to the currently viewed member.
So, what's the best course of action here? Should I do something with the relation? Or build a custom filter in JavaScript? How can I make the Stuff related to Contact if it's at all possible?
The image below shows the available conditions for the related entities. I notice that none of them relates to Contact, though. Do I need to activate it somehow or am I approaching it from a totally wrong angle?
So to give you more detail, you add the grid on the form:
(This is coming from the contact Form edit, after you press add subgrid)
you select there only related records, this are the stuff record i created:
As you can see only 3 of them has a lookup pointing to a valid contact, from there if you look at the grid, is showing only the related ones as you selected during the grid creation:
In any case i update the answer this is how the relationship is defined, and is a simple lookup created from the stuff entity:

Dynamically add input boxes to an edit form in joomla 2.5

I followed this tutorial on how to build a component for joomla 2.5, but now I am stuck.
What I want to do:
Besided thoses field defined in admin\models\forms\.xml I want to dynamically add form fields. The field list should be read from database.
I have a:
main table #__tours(id, title),
field list table #__tourfields(id,lable,description,position)
field value table #__tourfieldvalues(tourid,fieldid,fieldvalue)
#__tourfields contains a list of additional fields, that the user may want to specify for each entry in #__tours. #__tourfieldvalues would contain the values for the additional fields.
So now I need to figure out how to add input boxes to the edit form for each row in #__tourfields, read the values in #__tourfieldvalues for the currently to display entry of #__tours.
How can I do this?
This is very complex question. Subject to small book :)
In general you have to create class for every field type and initiate this class for every field in #__tourfields. This class have to extend JFormField and have getInput() method overridden.
Then in cycle you fetch your fields.
Something like this. But I believe you have to have more specific question. This one sounds like "How to create CMS like Joomla from scratch?"

Changing the model's attributes - adding or removing attributes

I am working on a MVC3 code first web application and after I showed the first version to my bosses, they suggested they will need a 'spare' (spare like in something that's not yet defined and we will use it just in case we will need it) attribute in the Employee model.
My intention is to find a way to give them the ability to add as many attributes to the models as they will need. Obviously I don't want them to get their hands on the code and modify it, then deploy it again (I know I didn't mention about the database, that will be another problem). I want a solution that has the ability to add new attributes 'on the fly'.
Do any of you had similar requests and if you had what solution did you find/implement?
I haven't had such a request, but I can imagine a way to get what you want.
I assume you use the Entity Framework, because of your tag.
Let's say we have a class Employee that we want to be extendable. We can give this class a dictionary of strings where the key-type is string, too. Then you can easily add more properties to every employee.
For saving this structure to the database you would need two tables. One that holds the employees and one that holds the properties. Where the properties-table has a foreign-key targeting the employee-table.
Or as suggested in this Q&A (EF Code First - Map Dictionary or custom type as an nvarchar): you can save the contents of the dictionary as XML in one column of the employee table.
This is only one suggestion and it would be nice to know how you solved this.

Resources