Support the ongoing development of Laravel.io →
Database Laravel.io Laravel

I am using Laravel 5.2 Package dimsav laravel-translatable 6.*

This is my worked controller

$about = new About();
        $about->link = $request->link;
        $about->save();

        $localization = $request['localization'];
        //dd($localization);
        // check if locales arabic and english only
        $locales = array_keys($localization);
        foreach ($locales as $locale) {
            if (!in_array($locale, array('en', 'ar'))) {
                Session::flash('message', 'Lang Error');
                return Redirect::back();
            }
        }

        foreach ($localization as $locale => $parameters) {
            $about->translateOrNew($locale)->title = $parameters['title'];
            $about->translateOrNew($locale)->details = $parameters['details'];
        }

        $about->save();

but when I try to use mass-assignment

$input = $request->all();

        $localization = $input['localization'];
        // check if locales arabic and english only
        $locales = array_keys( $localization );
        foreach ( $locales as $locale ) {
            if ( ! in_array( $locale, array( 'en', 'ar' ) ) ) {
                Session::flash( 'message', 'Lang Error' );

                return Redirect::back();
            }
        }


        foreach ( $localization as $locale => $parameters ) {
            $input->translateOrNew( $locale )->title   = $parameters['title'];
            $input->translateOrNew($locale)->details = $parameters['details'];
        }
dd($input);


About::create( $input );

Got an error

> Call to a member function translateOrNew() on a non-object

any help please what I am doing wrong here.

Last updated 3 years ago.
0

Ok, so I'm guessing you're getting the error in 2nd foreach loop, since I don't see the error line in your post. dd($input) in there, because it's not an object, it's either a string or an array.

You're calling a function from an object that isn't there, at least It's not called input

0

Sign in to participate in this thread!

Eventy

Your banner here too?

johnef johnef Joined 18 May 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.