Thanks for the great work you are doing, first of all, but I would like to know the method to implement the fields translated in the frontend, any ideas?
In controller
Post::whereFeatured(1)->whereNotNull('image')->get()->translate()
Voyager::model('Post')->whereFeatured(1)->whereNotNull('image')->get()->translate()
With this way you translate the whole model but you lose pagination and some other functions like format on timestamps ( Carbon gone ).
Another way is this
$featured_posts = Post::whereFeatured(1)->whereNotNull('image')->get()
$featured_posts = Voyager::model('Post')->whereFeatured(1)->whereNotNull('image')->get()
and in blade
foreach bla bla bla
$featured_post->getTranslatedAttribute('title')
``
with this way you translate only attributes you want and you don't lose any functionalities.
Another approach is this:
$featured_posts = Voyager::model('Post')->whereFeatured(1)->whereNotNull('image')->get();
if($featured_posts){
foreach ($featured_posts as $featured_post){
$featured_post->translation = $featured_post->translate();
}
$data['featured_posts'] = $featured_posts;
}
Not sure if last one i good one
Thanks vaggelis2018, this has been enough, in case someone else serves:
Gracias vaggelis2018, con esto ha sido suficiente, por si a alguien m谩s le sirve:
Blade
{{ $post->getTranslatedAttribute('title') }}
Controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use TCG\Voyager\Models\Post;
class BlogController extends Controller
{
public function index() {
$posts = Post::paginate(5);
return view('blog.blog', compact('posts'));
}
}
Closing as the question has been answered.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
Thanks vaggelis2018, this has been enough, in case someone else serves:
Gracias vaggelis2018, con esto ha sido suficiente, por si a alguien m谩s le sirve:
Blade
{{ $post->getTranslatedAttribute('title') }}Controller: