php - Laravel Nova - 隐藏相关资源上的更新图标(编辑附件)

标签 php laravel laravel-nova laravel-5.8

有谁知道如何去掉相关资源详细信息页面上的更新图标?

我说的是右边的图标;

Nova Backend

事件和时隙具有多对多关系。

它们是这样关联的;

App/TimeSlot.php

public function events()
{
    return $this->belongsToMany('App\Event');
}

应用程序/事件.php

public function timeSlots()
{
    return $this->belongsToMany('App\TimeSlot');
}

我也有针对每个模型的 Nova 资源和政策。

在我的时隙策略中,更新设置为返回 false。

App/Nova/Policies/TimeSlotPolicy.php

/**
 * Determine whether the user can update the time slot.
 *
 * @param  \App\User  $user
 * @param  \App\TimeSlot  $timeSlot
 * @return mixed
 */
public function update(User $user, TimeSlot $timeSlot)
{
    return false;
}

并且在我的事件策略中,attachAnyTimeSlot 和 detachTimeSlot 都设置为返回 false;

App/Nova/Policies/EventPolicy.php

/**
 * Determine whether the user can attach a time slot to an event.
 *
 * @param  \App\User  $user
 * @param  \App\Event $event
 * @return mixed
 */
public function attachAnyTimeSlot(User $user, Event $event)
{
   return false;
}

/**
 * Determine whether the user can detach a time slot from an event.
 *
 * @param  \App\User  $user
 * @param  \App\Event $event
 * @param  \App\TimeSlot $timeSlot
 * @return mixed
*/
public function detachTimeSlot(User $user, Event $event, TimeSlot $timeSlot)
{
    return false;
}

后者去掉了分离关联资源的垃圾桶图标。

似乎没有什么可以摆脱编辑图标。

当我点击它时,我什么也做不了。

Nova Backend 2

出于显而易见的原因,我根本不希望它出现。

有谁知道如何删除它吗?

最佳答案

在你的 EventPolicy 中定义

public function attachTimeSlot(User $user, Event $event, TimeSlot $timeSlot)
{
   return ! $event->timeslots->contains($timeslot);
}

取自此github issue , 查看更多详细信息

关于php - Laravel Nova - 隐藏相关资源上的更新图标(编辑附件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55704353/

相关文章:

php连接mysql并提交数据

php - 如何在 Eclipse 中调试 php 脚本时添加参数?

php - 在 1 个有 2 行的字段中仅选择 1 行

javascript - Bootstrap Datetimepicker 剩余秒数

php - 在curl_getinfo中未返回“redirect_url”

php - 识别第二个实例

php - Laravel 内部服务器 vs XAMPP/WAMP 服务器?

laravel - 如何从laravel nova的资源列表中删除所有复选框?

laravel-nova - Laravel Nova 设置全局 DateTime 格式

laravel - 更改 Nova 资源的资源 URL