-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from omaralalwi/enhancements-for-update-or-create
enhancments for Update or create
- Loading branch information
Showing
10 changed files
with
293 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Lexi Translate Examples | ||
|
||
### First Example | ||
|
||
the following controller handle update or create translations from request | ||
|
||
```php | ||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Post; | ||
|
||
class SetTranslationsController extends Controller | ||
{ | ||
public function handle() | ||
{ | ||
$service = Post::create([ | ||
'name' => 'original name', | ||
'description' => 'original description', | ||
]); | ||
|
||
$service->setTranslations([ | ||
'en' => [ | ||
'name' => 'English Name' | ||
'description' => 'English description' | ||
], | ||
'ar' => [ | ||
'name' => 'اسم باللغة العربية' | ||
'description' => 'وصف باللغة العربية' | ||
], | ||
]); | ||
|
||
return view('set_translations', compact('service')); | ||
} | ||
} | ||
|
||
``` | ||
|
||
--- | ||
|
||
### second example from blade file to controller | ||
|
||
#### blade file | ||
|
||
```php | ||
<form action="{{ route('translations.store', $post->id) }}" method="POST"> | ||
@csrf | ||
|
||
@foreach (lexi_locales() as $locale) | ||
<h4>{{ strtoupper($locale) }}</h4> | ||
|
||
@foreach ($post->getTranslatableFields() as $field) | ||
<div> | ||
<label for="{{ $field }}_{{ $locale }}">{{ ucfirst($field) }} ({{ $locale }}) </label> | ||
<input type="text" name="translations[{{ $locale }}][{{ $field }}]" | ||
value="{{ $post->transAttr($field, $locale) }}" /> | ||
</div> | ||
@endforeach | ||
@endforeach | ||
|
||
<button type="submit">Save Translations</button> | ||
</form> | ||
``` | ||
|
||
### in controller | ||
```php | ||
use Illuminate\Http\Request; | ||
use App\Models\Post; | ||
|
||
class TranslationsController extends Controller | ||
{ | ||
public function store(Request $request, $id) | ||
{ | ||
$translations = $request->input('translations'); | ||
$post = Post::findOrFail($id); | ||
$post->setTranslations($translations); | ||
|
||
return redirect()->back()->with('success', 'Translations updated successfully!'); | ||
} | ||
} | ||
|
||
``` | ||
|
||
**Validations will coming Soon** . | ||
|
Oops, something went wrong.