Pixelairport's avatar

Pixelairport was awarded Best Answer+1000 XP

2mos ago

I just found out I can replace core.blade.php with core.md ... that also works.

Pixelairport's avatar

Pixelairport wrote a reply+100 XP

2mos ago

I just found out I can replace core.blade.php with core.md ... that also works.

Pixelairport's avatar

Pixelairport started a new conversation+100 XP

2mos ago

I want to structure my coding standards in md files in a composer package. At the moment i create a core.blade.php in my package for boost and this works. Now I want to create a directory /package/resource/markdown/ ... to load files from this directory instead put all in the core.blade.php. Is that possible? Because I dont understand how? I already tried it like in spatie package: https://github.com/spatie/boost-spatie-guidelines/blob/main/resources/boost/guidelines/core.blade.php and also tried it like in filament/blueprint, where its just say:

**Start here**: Read
`/vendor/.../overview.md`
Pixelairport's avatar

Pixelairport wrote a reply+100 XP

4mos ago

Thx @glukinho . I already tried it. Sorry, my question was not so clear. I saw in docs there is rules, but it does not work. But now its clear. It works, but only backend. I hoped it also works for the frontend fields. I will do it the filament way and use my DTOs for the backend and for filament I will go on set everything manual for each field.

Pixelairport's avatar

Pixelairport started a new conversation+100 XP

4mos ago

Does anybody know, if it is possible to do something like:

TextInput::make('title')->rules(['required','max:32'])

instead of

TextInput::make('title')->maxLength(32)->required(),

because I want to use Spatie DTO also for Filament forms or is that a bad idea?

Pixelairport's avatar

Pixelairport was awarded Best Answer+1000 XP

4mos ago

If also the AI does not answer, you know you ask a boring questions :P ....

I think I have the solution. The code above seems ok. If I inject different user models in test and live code I remove use Workbench\Models\User or use App\Models\User and in the function I do public function viewAny($user) without to define User before $user. This ist the function. For all who also use Spatie Permissions like me, you also have to set the guard as second parameter in the hasPersmissionTo method. It took me a bit time to find out. But I think this is the best workaround for Spatie Permissions with Policies in Orchestra Workbench.


    public function viewAny($user): bool
    {
        if($user->hasPermissionTo(PostPermission::VIEW_ANY->value, 'web')) {
            return true;
        }

        return false;
    }

Pixelairport's avatar

Pixelairport wrote a reply+100 XP

4mos ago

If also the AI does not answer, you know you ask a boring questions :P ....

I think I have the solution. The code above seems ok. If I inject different user models in test and live code I remove use Workbench\Models\User or use App\Models\User and in the function I do public function viewAny($user) without to define User before $user. This ist the function. For all who also use Spatie Permissions like me, you also have to set the guard as second parameter in the hasPersmissionTo method. It took me a bit time to find out. But I think this is the best workaround for Spatie Permissions with Policies in Orchestra Workbench.


    public function viewAny($user): bool
    {
        if($user->hasPermissionTo(PostPermission::VIEW_ANY->value, 'web')) {
            return true;
        }

        return false;
    }

Pixelairport's avatar

Pixelairport started a new conversation+100 XP

4mos ago

I use spatie permissions in my package and want to test with orchestra. That means I need Workbench\Models\User::class instead of User\Models\User::class as user model. I set this in phpunit.xml:

<env name="AUTH_MODEL" value="Workbench\Models\User::class"/>

Now I want to test the policy. But the user model implements spatie permissions trait and then the user has the function $user->hasPermissionTo('viewAny').

The question is, how to make the policy now. In the past I had:

    use App\Models\User;

    public function viewAny(User $user): bool
    {
        if($user->hasPermissionTo(PostPermission::VIEW_ANY->value)) {
            return true;
        }

        return false;
    }

that is not possible because now I use workbench for test. The user model should come from my config. So I need to delete use App\Models\User;. AI and Google says I should use use Illuminate\Contracts\Auth\Authenticatable; instead, but then my function to check permission is not available. But how should I inject the correct user model at data binding? Or is it a normal way to delete the type in this situation? I mean ...

// do
public function viewAny($user): bool
// instead of
public function viewAny(Authenticatable $user): bool

Does anybody know, what is the best or the standard way here?

Pixelairport's avatar

Pixelairport was awarded Best Answer+1000 XP

5mos ago

Ok... I have the solution:

$this->call('vendor:publish', ['--provider' => 'Spatie\Permission\PermissionServiceProvider']);
Pixelairport's avatar

Pixelairport wrote a reply+100 XP

5mos ago

Ok... I have the solution:

$this->call('vendor:publish', ['--provider' => 'Spatie\Permission\PermissionServiceProvider']);
Pixelairport's avatar

Pixelairport wrote a reply+100 XP

5mos ago

I just thought it is a good idea to create a command and use:

$this->call('vendor:publish --provider=Spatie\Permission\PermissionServiceProvider --tag=migrations');

But this shows also an error:

Command "vendor:publish --provider=Spatie\Permission\PermissionServiceProvider --tag=migrations" is not defined. Did you mean one of these?  

  ⇂ vendor:publish

So it seems there is the same problem. It think maybe it is just a syntax problem, but cant find a solution.

Pixelairport's avatar

Pixelairport wrote a reply+100 XP

5mos ago

- ['vendor:publish', '--provider=Spatie\Permission\PermissionServiceProvider', '--force']

is also not working.

Pixelairport's avatar

Pixelairport started a new conversation+100 XP

5mos ago

I use orchestra testbench and in my testbench.yaml I have:

...
  build:
    - asset-publish
    - create-sqlite-db
    - db-wipe
    - vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
    - migrate-fresh
...

But --provider="Spatie\Permission\PermissionServiceProvider" ist not used, when I use workbench:build. When I only use vendor:publish in testbench.yaml, I will be asked what provider to use. Then it works. I can select Spatie\Permission\PermissionServiceProvider.

But how can I preselect the provider in my testbench.yaml? Also wenn I use vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" in my terminal it works.