I have a menu setup using https://github.com/harimayco/wmenu-builder and it's working quite well until it comes to trying to display the permalinks by getting the menu items parent but for it to keep going to get all parents.
So for instance, I want to get the permalink structure of Financial Provisions this has a parent id of 3 so the final permalink structure would be:
/services-for-you/contentious-probate/financial-provisions
I can't for the live of me workout the best way of doing this, do I just create a relationship of it's self?
For sure that's a good way to do it. There is nothing wrong with creating a relation from a table back to itself - in fact this is a great way to implement data-structures in your database. For your case, I'd expect something like:
public function parent()
{
return $this->belongsTo(MenuItem::class, 'parent');
}
As a note - I'd probably recommend making the column ->unsigned()->nullable() in your migration. This way you don't have to use a 0-id to represent a root node, but a null-parent would be a little more semantic. Since 0-id record doesn't actually exist in your database.
Along the same lines, you could extend this concept and build additional tree-operations into your model, if you think you'll need them:
public function ancestors(); // or parents()...
public function children(); // hasMany()
// ... siblings?