有谁知道如何去掉相关资源详细信息页面上的更新图标?
我说的是右边的图标;
事件和时隙具有多对多关系。
它们是这样关联的;
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;
}
后者去掉了分离关联资源的垃圾桶图标。
似乎没有什么可以摆脱编辑图标。
当我点击它时,我什么也做不了。
出于显而易见的原因,我根本不希望它出现。
有谁知道如何删除它吗?
最佳答案
在你的 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/