I thought that taking this task literally will be boring. Preparing a simple api based on laravel default behavior is not challenging. And since I am not familiar with laravel framework it will be hard for me to do defend my solution based on basic cases described in documentation. During the interview video-call we were talking about separating storage in CQS, Eloquent active record "anti pattern" and idea of defense programing. So I thought that could be funny if I'll play with the convention a little. So I decided that I'll try to prepare a domain model separated from framework logic, store it as serialized string in file and use eloquent as a view model stored in sqlite database. I realized that it was a mistake after a couple of hours... But I decided to be stubborn. So it took a lot of my time and I still haven't finished. I've prepared some basic skeleton... But it's still a lot of work left. It would be a lot easier if I just play with database tree structure map to eloquent models
Fork or Download this repository and implement the logic to manage a menu.
A Menu has a depth of N and maximum num 11ber of items per layer M. Consider N and M to be dynamic for bonus points.
It should be possible to manage the menu by sending API requests. Do not implement a frontend for this task.
Feel free to add comments or considerations when submitting the response at the end of the README
.
- Home
- Home sub1
- Home sub sub
- [N]
- Home sub sub
- Home sub2
- [M]
- Home sub1
- About
- [M]
Create a menu.
{
"field": "value"
}
{
"field": "value",
"max_depth": 5,
"max_children": 5
}
{
"field": "value"
}
{
"field": "value",
"max_depth": 5,
"max_children": 5
}
Get the menu.
{
"field": "value"
}
{
"field": "value",
"max_depth": 5,
"max_children": 5
}
Update the menu.
{
"field": "value"
}
{
"field": "value",
"max_depth": 5,
"max_children": 5
}
{
"field": "value"
}
{
"field": "value",
"max_depth": 5,
"max_children": 5
}
Delete the menu.
Create menu items.
[
{
"field": "value"
},
{
"field": "value"
}
]
[
{
"field": "value",
"children": [
{
"field": "value",
"children": []
},
{
"field": "value"
}
]
},
{
"field": "value"
}
]
[
{
"field": "value"
},
{
"field": "value"
}
]
[
{
"field": "value",
"children": [
{
"field": "value",
"children": []
},
{
"field": "value"
}
]
},
{
"field": "value"
}
]
Get all menu items.
[
{
"field": "value"
},
{
"field": "value"
}
]
[
{
"field": "value",
"children": [
{
"field": "value",
"children": []
},
{
"field": "value"
}
]
},
{
"field": "value"
}
]
Remove all menu items.
Create an item.
{
"field": "value"
}
{
"field": "value"
}
Get the item.
{
"field": "value"
}
Update the item.
{
"field": "value"
}
{
"field": "value"
}
Delete the item.
Create item's children.
[
{
"field": "value"
},
{
"field": "value"
}
]
[
{
"field": "value",
"children": [
{
"field": "value",
"children": []
},
{
"field": "value"
}
]
},
{
"field": "value"
}
]
[
{
"field": "value"
},
{
"field": "value"
}
]
[
{
"field": "value",
"children": [
{
"field": "value",
"children": []
},
{
"field": "value"
}
]
},
{
"field": "value"
}
]
Get all item's children.
[
{
"field": "value"
},
{
"field": "value"
}
]
[
{
"field": "value",
"children": [
{
"field": "value",
"children": []
},
{
"field": "value"
}
]
},
{
"field": "value"
}
]
Remove all children.
Get all menu items in a layer.
[
{
"field": "value"
},
{
"field": "value"
}
]
Remove a layer and relink layer + 1
with layer - 1
, to avoid dangling data.
Get depth of menu.
{
"depth": 5
}
- 10 vs 1.000.000 menu items - what would you do differently?
- Write documentation
- Use PhpCS | PhpCsFixer | PhpStan
- Use cache
- Use data structures
- Use docker