<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
underwear / laravel-translatable-json-resource example snippets
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Underwear\LaravelTranslatableJsonResource\TranslatableJsonResource;
class ArticleResource extends TranslatableJsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title, // translatable field,
'body' => $this->body, // translatable field
'created_at' => $this->created_at
];
}
}
use App\Http\Resources\ArticleResource;
use App\Models\Articles;
Route::get('/article/{id}', function ($id) {
$article = Article::findOrFail($id);
$locale = 'en';
return new ArticleResource($article, $locale);
});
use App\Http\Resources\ArticleResource;
use App\Models\Articles;
Route::get('/articles', function () {
$articles = Article::all();
$locale = 'ru';
return ArticleResource::collection($articles, $locale);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.