PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Unsolved
cyberekklesia

Oct 26th, 2022 02:25 PM

Hello Bobby

This is a continuation of the Role and Permissions Question.

I had issues with Category, Post and Thread Policy. The forum stopped showing the "New Thread" button, and thread/post buttons. So, I did a fresh install (Wave and laravel-forum).

For sake of simplicity, I'm going to skip many steps and will not be adding coding at all. So, after installation,

  1. Used the forum as is. I was successfully been able to create a category and add a new thread. My observation: category/thread/post buttons were there like New reply, Quick reply and reply. Capture.JPG
  2. Added BREAD to Forum Thread (TeamTeaTime\Forum\Models\Thread).
  3. Went back to the thread page, and refresh it. My observation: I lost most of the thread buttons and other controls. Capture.JPG
  4. I removed the Bread, and the buttons appeared again.

Same happened with Forum Category BREAD: TeamTeaTime\Forum\Models\Category. I assume that something similar will happen with Forum Post: TeamTeaTime\Forum\Models\Post. All this was without adding code.

Any suggestion? Thank you

bobbyiliev

Oct 27th, 2022 02:07 AM

Hey there,

Indeed I was able to replicate the same behavior on my end :/ somehow the Voyager permissions and the Forum permissions are getting in each other's way.

An alternative approach is not to rely on the voyager permissions, but use the Forum permissions and policies. So something like this:

  • Create a new Policy file with as you've done yesterday and in there define your custom permissions
  • An example of this would be:
    public function createThreads($user, Category $category): bool
    {
        if(auth()->user()->role->name == 'admin') {
                return true;
        } else {
                return false;
        }
    }

The above would check if the user is admin and allow them to create new threads, you can adjust it to match your needs.

  • You can get the base policies from the ./vendor/riari/laravel-forum/src/Policies/ directory and extend them as described in the Forumd docs

That way you don't have to use the BREAD functionality and you can have full control over the Forum policies based on your needs.

Let me know if this works for you!

cyberekklesia

Oct 27th, 2022 06:25 PM

Hey Bobby

Thank you for your response. I'm glad you could replicate the issue. I do appreciate your time and effort.

I think I finally found a solution... In order to be able to extend laravel-forum policies and manage role and permissions with Admin/Voyager, I had to add BREAD with an empty Model, and add the Model at my new policy files. Seems to work...

Hopefully I find no other issues... I need to move on!

Thank you Bobby

Report
1
bobbyiliev

Oct 28th, 2022 05:50 AM

Happy to hear that you've got it working! Good luck with your project!