簡體   English   中英

Laravel Nova - 隱藏相關資源上的更新圖標(附加編輯)

[英]Laravel Nova - Hide update icon (edit attached) on related resource

有誰知道我如何擺脫相關資源詳細信息頁面上的更新圖標?

我說的是右邊的圖標;

新星后端

事件和時隙具有多對多的關系。

他們是這樣相關的;

應用程序/TimeSlot.php

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

應用程序/事件.php

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

我也有適用於每個模型的 Nova 資源和政策。

在我的時間段策略中,更新設置為返回 false。

應用程序/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;

應用程序/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;
}

后者擺脫了分離相關資源的垃圾桶圖標。

似乎沒有什么可以擺脫編輯圖標。

當我點擊它時,我什么也做不了。

新星后端 2

出於顯而易見的原因,我根本不希望它出現。

有誰知道如何刪除它?

在您的 EventPolicy 中定義

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

取自this github issue ,查看更多詳細信息

嗨,我有同樣的問題。 有沒有最新的解決方案?

到目前為止,我只找到了隱藏連接和分離的解決方案

在這里找到解決方案: https : //github.com/laravel/nova-issues/issues/1003#issuecomment-497008278

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM