benfreke
benfreke

Hi all

I'm attempting to create a menu management plugin, and I want to use nested sets. So rather than write it from scratch, I am trying to use this: https://github.com/etrepat/baum

Unfortunately, I can't for the life of me figure out how to install this in a plugin in October, as the instructions for it assume it is a native Laravel app, and since I've never used Laravel before I don't know enough to get around this problem.

If anyone has some tips on how to do this, or even just some keywords I should be looking for in the Laravel documentation it would be greatly appreciated. I've looked over the Laravel Packages page but couldn't see anything in there that I could use in the boot method of the plugin?

sorentruelsen339
sorentruelsen339

Try use "Composer" to update the vendor and then add the service provider in app/config/app.php

Søren

tallcoder1340
tallcoder1340

I'm trying to figure out how to do the same thing ... not having any luck though

Flynsarmy
Flynsarmy

October supports NestedSets out of the box. I'm using it in my Menu Lists plugin.

benfreke
benfreke

Yeah, i figured it out for my menu plugin as well. I ended up not using the service provider because, as Flynsarmy says, October has it already.

use \October\Rain\Database\Traits\NestedTree;

Add that in your model and you get funky Nested Set behaviour you want.

p.s. That looks like a really nice plugin Flynsarmy, nice and clean interface too!

Francesco
Francesco

Hi Flynsarmy can i ask you some advice or tutorial link for this feature? i want to add nested categories to my app

Tnx in advice. Francesco

benfreke
benfreke

Hi Francesco

Step 1. Add this line use \October\Rain\Database\Traits\NestedTree; inside your model class.

Step 2. Use the new methods available on the model. That line is step 1 gives your class access to those methods.

For example, in my plugin I use getChildrenCount to see if a menu item has any child items. In the twig template, that's called like this if (menu_item.getChildrenCount) { create submenu }

Obviously that's not the exact code, as I'm not on that machine at the moment to look it up. From memory, the trait it uses is in vendor/rainlab/october/rain/database/traits/NestedSetTrait.php

That should definitely be enough to get you started. If not, have a look at the categories in the RainLab plugin Blog, as that is what I based my entire Nested Set code on.

Last updated

adis.osmonov
adis.osmonov

So how to add service provider in plugin?

tallcoder1340
tallcoder1340

Not sure ... I've had to go back to using a base Laravel install for my projects because I was unable to use packages within an OctoberCMS project. If that can be explained ... I'd love to use this CMS. But, that's a deal breaker for me.

Flynsarmy
Flynsarmy

@benfreke, @adis.osmonov, @tallcoder1340 I did this yesterday with my DebugBar plugin.

1. Require the third party plugin in

You firstly need to composer require the third party package into yours. Laravel packages often require laravel, so you'll get an entirely new laravel distro downloaded right into your plugin. There is no perfect solution for this yet until this issue is resolved, but it doesn't matter anyway - it won't affect October or your plugin. Just remember to add vendor/ to your .gitignore before uploading to git!

2. Register the plugins Service Provider

In your Plugin.php's boot() method, add \App::register('\Third\Party\ServiceProvider');. This is how you register a third party ServiceProvider automatically.

3. Register any Alias's

In your Plugin.php's boot() method under any ServiceProvider lines, if you then need to add an Alias it can be done with $alias = \Illuminate\Foundation\AliasLoader::getInstance()->alias('YourAlias', 'Third\Party\Facade');

See my implementation here.

Last updated

tallcoder1340
tallcoder1340

Ah! Beautiful ... thanks so much!

d.negativa
d.negativa

Hi guys!
Thanks for the tip on the registration service provider!
But I am having difficulties with the configuration of mongodb for my plugin. I use this package jenssegers/laravel-mongodb.
Where do I place an array with the configuration mongodb?
And how can I register this configuration?


'mongodb' => array(
    'driver'   => 'mongodb',
    'host'     => 'localhost',
    'port'     => 27017,
    'username' => 'username',
    'password' => 'password',
    'database' => 'database'
),

Last updated

Flynsarmy
Flynsarmy

If you have a separate issue, please put it in its own post.

d.negativa
d.negativa

Thank you Flynsarmy!
I have moved my question here.

ScDraft
ScDraft

@Flynsarmy, Thanks!

Webp
LukeTowers
LukeTowers

For any future reference on using Laravel Packages within October, see the article I wrote on this here: https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/

1-17 of 17