Back

Laravel 5.2: use mass-assignment with dimsav laravel-translatable


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.


Sign in to participate in this thread!



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