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="{{ route('offices.update', $office->id)}}/{{app()->getLocale()}}" method="POST">
{{csrf_field()}}
<div class="form-group">
<lebal>Name ({{ app()->getLocale() }})</lebal>
<input type="text" class="form-control" name="name" value="{{$office->name}}">
</div>
<div class="form-group">
<lebal>Content ({{ app()->getLocale() }})</lebal>
<textarea class="form-control" name="content">{{$office->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();
}
Try to replace your form tag with that:
<form action="{{ route('offices.update', ['id'=>$office->id,'locale'=>app()->getLocale()])}}" method="POST">