flipboxstudio / lumen-generator

A Lumen Generator You Are Missing
https://packagist.org/packages/flipbox/lumen-generator
MIT License
824 stars 126 forks source link

Fix make:policy command namespaces #119

Closed jorgemudry closed 2 years ago

jorgemudry commented 2 years ago

What does this Pull Request Do?

It fixes the issues with namespaces in the make:policy command.

How should this be manually tested?

  1. Install this version of the library: composer require flipbox/lumen-generator:dev-fix_make_policy_command
  2. Create a new plain policy: php artisan make:policy MyPolicy
  3. You should end up with a new policy looking like this:
    
    <?php

namespace App\Policies;

use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization;

class MyPolicy { use HandlesAuthorization;

/**
 * Create a new policy instance.
 *
 * @return void
 */
public function __construct()
{
    //
}

}

4. Create a new policy using a model: `php artisan make:policy MyPolicy --model=Post`
5. You should end up with a new policy looking like this:
```php
<?php

namespace App\Policies;

use App\Models\Post;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class MyPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any posts.
     *
     * @param  \App\Models\User  $user
     * @return mixed
     */
    public function viewAny(User $user)
    {
        //
    }

    /**
     * Determine whether the user can view the post.
     *
     * @param  \App\Models\User  $user
     * @param  \App\Models\Post  $post
     * @return mixed
     */
    public function view(User $user, Post $post)
    {
        //
    }

    /**
     * Determine whether the user can create posts.
     *
     * @param  \App\Models\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        //
    }

    /**
     * Determine whether the user can update the post.
     *
     * @param  \App\Models\User  $user
     * @param  \App\Models\Post  $post
     * @return mixed
     */
    public function update(User $user, Post $post)
    {
        //
    }

    /**
     * Determine whether the user can delete the post.
     *
     * @param  \App\Models\User  $user
     * @param  \App\Models\Post  $post
     * @return mixed
     */
    public function delete(User $user, Post $post)
    {
        //
    }
}

Any background context you want to provide?

N/A

What are the relevant tickets?

make:policy problem #112

Any extra info?

oprah