spatie / laravel-translatable

Making Eloquent models translatable

Home Page:https://spatie.be/docs/laravel-translatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

attributes with json not set locale

MwSpaceLLC opened this issue · comments

Hi there,

Today we test this awesome package.

So for use it, with setLocale, but the query return json, not input translate:

example

        dd(
            Product::query()
//                ->where('lang', app()->getLocale())
                ->when($request->query('search'), fn($query) => $query->where('title', 'like', "%{$request->query('search')}%"))
                ->with('categories')
                ->orderByDesc('created_at')->paginate()
        );

result:

Illuminate\Pagination\LengthAwarePaginator {#623 ▼ // packages\mwspace\admin\src\Controllers\Core\ProductController.php:24
#items: Illuminate\Database\Eloquent\Collection {#618 ▼
#items: array:1 [▼
0 => MwSpace\Admin\Models\Product {#614 ▼
#connection: "mysql"
#table: "mwspace_products"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:11 [▼
"id" => 1
"slug" => "{"it":"products"}"
"name" => "{"it":"products"}"
"title" => "{"it":"products"}"
"description" => "{"it":"products"}"
"content" => "{"it":null}"
"price" => null
"enabled" => 0
"created_at" => "2023-09-28 12:12:01"
"updated_at" => "2023-09-28 12:12:01"
"deleted_at" => null
]
#original: array:11 [▶]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶]
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:7 [▶]
#guarded: array:1 [▶]
+translatable: array:5 [▶]
#translationLocale: null
}
]
#escapeWhenCastingToString: false
}
#perPage: 15
#currentPage: 1
#path: "http://127.0.0.1:8000/it/mwspace/products"
#query: []
#fragment: null
#pageName: "page"
+onEachSide: 3
#options: array:2 [▶]
#total: 1
#lastPage: 1
}