mercredi 16 décembre 2020

add multiple langue using Astrotomic / laravel-translatable package and laravel

i am new in laravel and use Astrotomic / laravel-translatable package for translation i have problem when i want to add two langue at same time. i have name_en,name_ar,discription_an,disriptionar as inputs fields. i get this error Creating default object from empty value so how can I solve my problem this is link of package https://github.com/Astrotomic/laravel-translatable

// start add data
    public function store(CategoryRequest $request)
    {
    
            // prepare data
            $validatedData = array(
                'url' => $request->url,
                'slug' => $request->slug,
                'status' => $request->status,
                'last_updated_by' => auth('admin')->user()->id,
                'created_by'      => auth('admin')->user()->id,
                'created'         => time(),
            );
            $translated = array(
                'name_en' => $request->name_en,
                'name_ar' => $request->name_ar,
                'description_en' => $request->description_en,
                'description_ar' => $request->description_ar,
            );
            //start define categoru is sub or main
            $request ->sub ==1 ?  $validatedData['parent_id'] = $request ->category_id: $validatedData['parent_id']=null;
            // start update data
            DB::beginTransaction();
            $add = Category::create($validatedData);
            $id = $add->id;
    
            // strat update category report
            $categoryReport = CategoryReport::create(
                ['status'           =>$validatedData['status'],
                 'category_id'      =>$id,
                 'created_by'       =>$validatedData['created_by']
                 ,'last_updated_by' =>$validatedData['last_updated_by']]);
            $add->translate('ar')->name = $translated['name_ar'];
            $add->translate('en')->name = $translated['name_en'];
            $add->translate('ar')->description = $translated['description_ar'];
            $add->translate('en')->description =$translated['description_en'];
            $add ->save();
        DB::commit();
            return redirect()->back()->with('success','تم اضافه البيانات بنجاح');
    
    
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/387Mkfv
via IFTTT

Aucun commentaire:

Enregistrer un commentaire