I’m using https://github.com/artesaos/seotools package for seo.
I am trying to override getCanonical function located at https://github.com/artesaos/seotools/blob/master/src/SEOTools/SEOMeta.php and make it’s output as lowercase. Could you please guide me how can I do this?
2
Answers
You can try following :
Step 1:
Create a child class extending SEOMeta class and override the
getCanonical
function.Step 2:
Create the Service Provider for overridden class. First parameter of
bind
function must be same as facade accessor ofSEOMeta
Facade (check here). Register this facade inconfig/app.php
after the service provider of seotools package. :You are all set. Hope this will help.
EDIT:
Above mention method will just override the single class. If you want to change the logic of more than one class. Best way is to fork the project. Change the code and push it to your fork. Use forked project as your composer dependency. Follow the link to know how to use private repository as composer dependency : https://getcomposer.org/doc/05-repositories.md#using-private-repositories
It’s very simple just like we overriding any parent class function in derived class.
Create your own class and extend your package class
SEOMeta
and re-declare function that you want to override and put your logic inside. Don’t forget to use namespace of your package classSEOMeta
at upper your custom class.Now use your custom class instead of package class inside your controller.
e.g