Code Monkey home page Code Monkey logo

Comments (14)

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024 1

In my case, to rapidly resolve my problem I only create my own trait. So I can interact with the Transtable functions normally. And in my case I only have 3 locales and no one of these are Indonesia, hehehehe

Thanks for your time, was very helpful!

trait OnaxTranlatable {

    public function addAllTranslations()
    {
        $locales = array_unique($this->getLocales());
        foreach ($locales as $locale) {
            $this->$locale = $this->getTranslation($locale);
        }
        return $this;
    }

}

from laravel-translatable.

sdebacker avatar sdebacker commented on May 31, 2024
$country->with('translations')->all() ?

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024

I'm Sorry, perhaps I don't explain myself correctly. O want to retrieve all translations from 1 selected model item, like so:

$model->find(1) ->get()->addAllTranslations();
...or simply:
$country->addAllTranslations();

The above code throw me an exception:

BadMethodCallException in Builder.php line 1856:
Call to undefined method Illuminate\Database\Query\Builder::all()

I submit a pull request that's explain what I target. https://github.com/dimsav/laravel-translatable/pull/66/files

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024

I'm using method injection with laravel 5. So (with the pull request), I'm be able to write this code in my controller, and all work fine!

public function edit(Country $country)
{
$locales = Locale::all();
$country->addAllTranslations();
return view('admin.country.edit', compact('country', 'locales'));
}

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024

And so I can generate and edit multiple languages on the same form, with laravel model binding.

from laravel-translatable.

sdebacker avatar sdebacker commented on May 31, 2024

Sorry it is get(), not all():

$country->with('translations')->get()

What I do for a single model is:

$country->with('translations')->find($id)

But of course I cannot use form model binding. I think a good approach would be to extend FormBuilder class with something that look in translations array.

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024

Thank you for the tip, I'm going further and try to do what you mean.
Sorry that it not works great with this technique of form model binding.

from laravel-translatable.

sdebacker avatar sdebacker commented on May 31, 2024

It would be nice to have a package for that job, I will be happy to contribute and use it.

from laravel-translatable.

wisepotato avatar wisepotato commented on May 31, 2024

My PR #63 fixes this issue. Sadly wont be implemented by the creator. you can use it I guess

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024

My own trait solved my problem for now. But I looking in your code.

from laravel-translatable.

wisepotato avatar wisepotato commented on May 31, 2024

It forces the language to which Form::model($model,.. Translates to

from laravel-translatable.

sdebacker avatar sdebacker commented on May 31, 2024

I made a package to use with BootForms that bind model values on translated fields : https://github.com/TypiCMS/TranslatableBootForms

from laravel-translatable.

wisepotato avatar wisepotato commented on May 31, 2024

That takes a whole other package to make this work. My PR fixes it innone go... Too bad

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on May 31, 2024

@sdebacker To bad is a new hole package, but I will try It eventually. Appears to be a nice Project!

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.