orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
137 stars 34 forks source link

New resource not being rendered in the menu #60

Closed ap1969 closed 2 years ago

ap1969 commented 2 years ago

Hi, I've got an odd problem, in a near pristine install of Laravel + Orchid + Crud.

I've created a new resource via artisan:

<?php

namespace App\Orchid\Resources;

use Orchid\Crud\Resource;
use Orchid\Screen\TD;
use Orchid\Screen\Fields\Input;

use App\Models\Plans;

class PlanResource extends Resource
{
  /**
   * The model the resource corresponds to.
   *
   * @var string
   */
  public static $model = Plans::class;

  /**
   * Get the fields displayed by the resource.
   *
   * @return array
   */
  public function fields(): array
  {
    return [
      Input::make("title")
        ->title("Title")
        ->placeholder("Enter title here"),
    ];
  }

  /**
   * Get the columns displayed by the resource.
   *
   * @return TD[]
   */
  public function columns(): array
  {
    return [
      TD::make("id"),

      TD::make("created_at", "Date of creation")->render(function ($model) {
        return $model->created_at->toDateTimeString();
      }),

      TD::make("updated_at", "Update date")->render(function ($model) {
        return $model->updated_at->toDateTimeString();
      }),
    ];
  }

}

And yet, it's not appearing the menu. I have no other resources, so the entire Resource section of the menu is missing.

I've narrowed it down to this section of ResourceFinder.php

 return collect($iterator)
            ->map(function (SplFileInfo $file) use ($directory) {
                return $this->resolveFileToClass($directory, $file);
            })
            ->filter(function (string $class) {
                return is_subclass_of($class, Resource::class)
                    && ! (new \ReflectionClass($class))->isAbstract();
            })
            ->toArray();

Specifically, is_subclass_of($class, Resource::class) - this is returning false.

Any ideas?

Regards, Andy

ap1969 commented 2 years ago

Aaaargh! It was some sort of disconnected between the resource filename and the model. I had defined the model and resource as Plans and PlansResource. I changed both of those to Plan and PlanResource, and now the menu has appeared.

Andy