繁体   English   中英

如何在浏览中仅显示来自 Voyager 中当前经过身份验证的用户/作者的帖子?

[英]How to show posts in browse only from current authenticated user/author in Voyager?

我需要在 Voyager 的浏览选项中显示仅来自登录网络的用户的帖子。 应该隐藏来自其他用户的帖子。 我是否需要为此制作其他控制器或编辑基于经过身份验证的用户的 voyagerbreadcontroller.php 查询?

预先感谢您的帮助。

这有效:

添加到AppServiceProvider.php register方法:

$this->app->bind('TCG\Voyager\Models\Post', function ($app) {
    return new App\Post;
});

创建扩展 Voyager 模型的新模型,并使用条件 addGlobalScope:

<?php

namespace App;

use TCG\Voyager\Models\Post as VoyagerPost;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;

class Post extends VoyagerPost
{
    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    protected static function boot()
    {
        parent::boot();

                // Customize your own rule here!
        if (\Request::is('management/*') && Auth::user()->canBlogSolo()) { 
            static::addGlobalScope('author', function (Builder $builder) {
                $builder->where('author_id', '=', Auth::user()->id);
            });
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM