Finding code for laravel category subcategories task - categories

Create Category Module with Parent and subcategory. Both Category handle in same table. Table name should be category_master with fields id, cat_parent_id, cat_title, cat_status, created-at, updated_at. Than after get all parent category with subcategory in frontend give checkbox the all category. max 3 parent category should be checkable at a time
I want code of this task.

Related

Getting records through parentID from CategoryCollection in Typo3

I am using CategoryCollection to get the records of a specific category ID, but the problem is it only loads the exact category for e.g I have parent > child and I have attached child category ID to a record and I select child category, then it shows me the record fine, but if I select parentID, then it does not show the child category record.
$collection = \TYPO3\CMS\Frontend\Category\Collection\CategoryCollection::load(
$categoryID,
true,
'tx_myextension_table_name',
'categories'
);
Is there any built-in way to get the records of all child category if I select parent ID from CategoryCollectionor do I have to write something custom for that?
Unfortunately there is no built-in solution for complex selections like this. You will indeed need to write your own logic which could work like this:
Find categories whose parent is your category
Repeat this recursively for every category found until you don't find any children for each category anymore
Do a custom IN() query with the list of category UIDs
If you have deep category trees, the list of category UIDs could be put in a custom cache. You can use the root category UID or a hash thereof as key. These cache entries should be tagged with sys_category. Alternatively you can add a sys_category_<uid> tag for every category UID in your list. This ensures that whenever something changes about one of the categories, the cache entries are dropped and you can rebuild the list.

Adding two non-relation Entities to DbContext that second entity use the first one's Id entity

in code first, When I want to save 2 related entities (for example Country entity and City entity), first, I create an instance of Country and second create an instance of City and put object of Country to navigation of City, at last SaveChanges.in this process Database, first, create the Country and then put its Id to CountryId field of City entity and save city to database. so now, I want to do the same but with non-related entities. this means I want to send 2 entity (without relationship) to DB, that fist, first one saved and second one get its Id, and use it, at last Save...

Symfony2 sonata admin bundle list mapping with mongodb odm

I have a collection 'Category' which contains its parent and childs in itself.
I am using sonata admin bundle to generate list. And I want is to list the categories in such a way that the default list should contains only the top level categories (i.e. only those categories which do not have parents).
And with a link to sub-categories list all the child categories of that particular parent category.
How could I do that?
First define method createQuery in your admin which restricts query to top parents.
When children are in collection self referenced to entity Category then you can display this collenction in list column.

How to handle autopopulated selects (from oneToMany relation) in Symfony form?

I have a ProductCategory class that has a parent and some children, properly annotated using Doctrine.
Then I have a ProductCategoryType (form class) that I use to render the html form.
Doctrine does its magic and creates a select box for parent which consists of previously added categories.
My problem: How to I prepend a default option (say '0' => 'No parent category') and how do I remove a particular category from list (ex: the currently edited category, so user can't select the very category to be its own parent)?
This can easily be achieved by using DataTransformers.
You can find more information in the documentation chapter How to use Data Transformers.

Entity Framework 4: Can you duplicate an entity and alter it based on filter condition

Is there a way within the entity framework designer to duplicate an entity and then apply a filter condition to both to make them unique. Id like to retain all navigation properties and what not.
For example, say in the database I had a table of orders. I could have two entities, one called IncompleteOrders and One called Complete based on the same table, with the complete having a filter specified on the database field 'complete'.
Thanks in advance
Yes, this is called Table per Hierachy
You have one physical table, which has a special, single, scalar column which is used as a discriminator.
Like this:
OrderId OrderName IsComplete
1 Foo 1
2 Bar 1
3 FooBar 0
Where IsComplete is the discriminator (BIT column, for example), so when you setup your entities on your EDMX, you create three entities:
1. Orders
2. CompleteOrders (derives from Orders)
3. InCompleteOrders (derives from Orders)
On the table mapping for Orders, you say "Maps to CompleteOrders, when IsComplete = 1", and "Maps to InCompleteOrders, when OrderType = 0".
Good writeup on TPH/Discriminator pattern here.