Code Monkey home page Code Monkey logo

Comments (9)

dimsav avatar dimsav commented on May 31, 2024

Hi @jufy,

this is an interesting question. Unfortunately, it is not possible with the current version to combine Ardent with Translatable without modifying the Translatable class. The reason is that both Ardent and Translatable classes extend Eloquent which means that the model will have to extend both, as shown below:

class Country extends \LaravelBook\Ardent\Ardent {
    // ...
}

class Country extends \Dimsav\Translatable\Translatable {
    // ...
}

Something like that is unfortunately not possible.

I will try to add the Translatable behaviour to a model by implementing an interface instead of extending Translatable. This way, it would be possible to make it work with Ardent, or any other package that forces the model to extend a class different than Eloquent.

Thanks for your message :)

from laravel-translatable.

jufy avatar jufy commented on May 31, 2024

It will be really great. I have made the localization of current project in a few hours, also include https://github.com/mcamara/laravel-localization and it works pretty good. If in next release it will work with Ardent I will include it to my must have list.

from laravel-translatable.

dimsav avatar dimsav commented on May 31, 2024

Unfortunately, avoiding the extending of Translatable to Eloquent is not possible at the moment as Laravel doesn't fire an event after a model is being instantiated and the attributes are filled. The solution I had in mind was with the use of this specific event. I am currently waiting for some feedback from the mentioned issue above.

from laravel-translatable.

jufy avatar jufy commented on May 31, 2024

Probably there is a variant to make your package work in a way used by this package:
https://github.com/cviebrock/eloquent-sluggable
https://github.com/cviebrock/eloquent-sluggable/blob/master/README-Ardent.md
https://github.com/laravelbook/ardent#modelhooks
There are build-in hooks for models. The solution is bit complex and more difficult to make your package run out of the box. However, the result will be great.

from laravel-translatable.

dimsav avatar dimsav commented on May 31, 2024

Sorry, I don't plan to add Ardent as a requirement for this package. That's why I am hoping to see these hooks added by the framework itself.

Sluggable doesn't extend Eloquent/Model so the nature of the conflict with Ardent is different.

from laravel-translatable.

torkiljohnsen avatar torkiljohnsen commented on May 31, 2024

Could it be possible to implement Translatable as a trait instead?

That way, translatable and any other -able behavior can be added without conflicting with PHP's single inheritance.

from laravel-translatable.

dimsav avatar dimsav commented on May 31, 2024

Good news, new version of the package comes with compatibility to other packages extending Eloquent such as Ardent.

Coming soon in version v2.0.0

Thanks to @torkiljohnsen for the idea of using traits.

from laravel-translatable.

torkiljohnsen avatar torkiljohnsen commented on May 31, 2024

Awesome 👍

from laravel-translatable.

dimsav avatar dimsav commented on May 31, 2024

Version updated to 2.0.0. I did a quick test in combination to Adrent and it seemed to work.

Update your composer.json and if there is a problem, feel free to open the issue back :)

from laravel-translatable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.