lundi 3 décembre 2018

How to update translatable model in laravel?

can you help me. What I am working wrong here, I have used this tutorial and create and store working well but when trying to edit/update it wont working, can you check my code. I am using this tutorial: https://mydnic.be/post/how-to-build-an-efficient-and-seo-friendly-multilingual-architecture-for-your-laravel-application

How should I write this route to work well.

Thank you very much on help. The code is written below, edit, controller and web.php (routes).

edit.blade.php:

@extends ('layouts.master')



@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Edit Office</div>

                <div class="card-body">
                 <form action="/" method="POST">
   

   <div class="form-group">
<lebal>Name ()</lebal>
<input type="text" class="form-control" name="name" value="">
</div>

  <div class="form-group">
<lebal>Content ()</lebal>
<textarea class="form-control" name="content"></textarea>
</div>



             <input type="submit" value="Save">

        </form>

                </div>
            </div>
        </div>
    </div>
</div>
@endsection

web.php:

Route::get('/office/edit/{id}/{locale}', 'OfficesController@edit')->name('offices.edit');

Route::post('/office/update/{id}/{locale}', 'OfficesController@update')->name('offices.update');

OfficesController.php

public function edit($id, $locale)
    {
      $office = Office::find($id);
      app()->setLocale($locale);
        return view('offices.edit')->with('office', $office);
    }


        public function update(Request $request, $id, $locale)
    {
         $office = Office::find($id);





            $office->translateOrNew($locale)->name = $request->name;
            $office->translateOrNew($locale)->content = $request->content; 



         $office->save();

         return redirect()->back();
    }



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

Aucun commentaire:

Enregistrer un commentaire