Backpack Laravel select2_from_ajax field returns results, but I can't select any - laravel

I'm implementing a 'select2_from_ajax' field using Backpack for Laravel.
I've implemented this in other places and it works correctly. But for some reason when implementing it this time it will not let me select any of the options and doesn't show the highlight when mousing over the options. It lists out the options correctly, I just can't select any of them.
The only thing I can think of is that the relationship it's trying to reference doesn't have a primary 'id' field in the database, but I'm not sure why that would affect this.
I have implemented both the index and show routes.

The issue was that the relationship field's primary key was not 'id' it was setup with a different column name.
I reworked the data structure so the foreign key referenced was pointing to a column labeled 'id'.

Related

AfterValidation Hook on BelongsToMany Field in Laravel Nova

I have a table "articles", a table "images" and a pivot table article_image with unique constraint on 2 columns: 'article_id' and an additional column 'order_nr'. Now I need to check the uniqueness of article_id/order_id in Laravel Nova when attaching an image to an article.
I already found a solution for a unique validation rule with 2 columns with a AfterValidation hook here:
https://grrr.tech/posts/2021/nova-multi-column-validation/
The problem is that this solution is referring to a resource by itself and not to a "pivot resource".
I tried to put the afterValidation method into the resources 'Article' and 'Image', but the method is simply not accessed from here.
How can I set a afterValidation hook on a pivot resource, thus a BelongsToMany field? Or am I completely a on the wrong track and anybody knows a better solution for that? Thank you in advance!

What table holds the category selections for the time_card table in ServiceNow

I'm using the ODBC connector to query time card data from the time_card table in ServiceNow, and there are two columns I'm wondering about: category and dv_category - those two fields are pulled from somewhere, and I do not know where. Is there are table that holds these values, or are they static on the UI and passed through?
The 'category' field is just a string(40) with a Choice List local to the field. So, it's not a reference field, just a drop down. The Choice List can be modified
I'm not finding the 'dv_category' field on the time_card table and I'm on Helsinki Patch 3. Can you clarify?
Editing to add the actual answer to the question : 'I believe the table you're looking for is called 'sys_choice''

Laravel Eloquent : two keys relationship

I have a first table named "Building", and this one gets a Type and a Level. There are multiple building with same type and level.
I have another table named "BuildingInfo", who also gets a Type and a Level. The couple Type/Level is unique on this table.
Is there a way to have a HasOne relationship on Building, giving me the matching BuildingInfo ? The problem being that there are two keys on each table to get it, and I can only specify one key for each table with HasOne().
Thank you.

Eloquent select specific columns

I am trying to select specific columns using Laravel's Eloquent but I am having some issues. I just want to SELECT quantity, prices from prices. I have tried
$prices = Price::select(array('quantity', 'price'))->whereMonthAndYearAndType($month,$year,'cpi')
->with(array('product'=>function($query){ $query->select('id','name'); }))
->with(array('market'=>function($query){ $query->select('id','name'); }))->get();
but I am getting Trying to get property of non-object
There is nothing in your code snippet that would produce that error. However, I suspect you are getting the error when you are trying to access fields on the eager loaded product or market relationships without checking for their existence.
A common problem with specifying select statements and eager loading relationships is that the local and foreign keys usually get left out. However, these are the values that Laravel uses to match up all the related models, so they need to be selected, as well.
If price belongsTo a product and price belongsTo a market, then you also need to select the prices.product_id and prices.market_id fields. If price hasOne product or price hasOne market, then you'll need to select the prices.id field, and the corresponding foreign keys on the eager loaded relationships (products.price_id or markets.price_id).
Though, even once this is resolved, it is still a good idea to check to make sure the related record exists before trying to access it. In a hasOne/belongsTo relationship, if the related record doesn't exist, the relationship property will be NULL. If you try to access a field on NULL, you'll get the error you're seeing.

how adding a fields to relationship Table in pivot table method using laravel

I want to design an online store. For each category of productions, we would have its own fields.
Connections between tables of fields and categories are done and displayed in the part of registration of productions.
At the end, the value of each field should be stored that it should contains the related table between table of fields and productions (in addition to/plus/+) the value of that field.
My problem is in this part and I want that this related table has an additional field that I could value it.
In the following figure, the picture of table and my connections are shown, if there is (any problem/ something wrong with it), I would appreciate you to help me.
View Relationship Images :
http://ir-up.ir/uploads/1416568805731.jpg
You'd simply need to add a withPivot when declaring the relationship:
return $this->belongsToMany('Role')->withPivot('foo', 'bar');
Extra attributes in pivot tables are covered in the docs, here - http://laravel.com/docs/4.2/eloquent#working-with-pivot-tables

Resources