Git Product home page Git Product logo

crud's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crud's Issues

Ability to add custom views to an item

Hi, I was wondering the possibility of adding additional custom views to the CRUD table view and it seems there's nowhere to hook into this.

private function getTableActions(Model $model): Group

I think roughly here is where a hook would be useful to add additional things such as "View PDF" etc (or whatever makes sense in an application)

View own records only on table

Hello,

I'm using this package with policies and everything works fine, except that everyone can see the data on table of the resource. Does anyone knows how to let users see only their own data?

Modal form edit and new actions

Would it be possible for the new and edit actions to be done with modal forms?
That the developer choose between modal and non-modal?
Thanks

Resources nav grouping issue

If displayInNavigation() is set to return false and would otherwise be the first Resource to be displayed in the admin sidebar nav, the ->title('Resources") type grouping never happens so all the Resources get grouped in with whatever grouping came before it.

There is another issue where Resources will have a random sort order in the nav depending on when they were added. Different servers can result in different sort orders. I suggest that the Resources sort order in nav defaults to alphabetical.

Issue with _retrieved_at on resource edit

Hi,

I am trying the crud package, it's really cool. However, I have an issue while editing a resource. I tried with a blank Laravel project User model. When saving my updates, I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '_retrieved_at' in 'field list' (SQL: update `users` set `_retrieved_at` = 2021-01-11T13:18:32.000000Z, `users`.`updated_at` = 2021-01-11 13:20:05 where `id` = 1)

The issue seems to be the parameter in the EditScreen commandBar in "src/Screens/EditScreen.php". Is there something I have to disable I don't know about?

Thanks a lot!

Override / extend a resource

There are some cases when I may want to override/extend an existing resource
I.e. I make some package that uses orchid crud and I want to be able to extend it from my app.

Can't figure out how to do it, can you please suggest me a solution?

Title resources is showing even though no permissions

title resources is showing even though the user does not have any of the appropriate permissions set for the resource menu items.
This can be fixed with a simple if statement in the "vendor\orchid\crud\src\Arbitrator.php" @ "registerMenu"

`private function registerMenu(Resource $resource, int $key): Arbitrator
{
if (! $resource::displayInNavigation()) {
return $this;
}

    View::composer('platform::dashboard', function () use ($resource, $key) {
        
        if (user()->hasAnyAccess('manage-crud-resource-*')) {
            $title = Menu::make()
                ->canSee($key === 0)
                ->title(__('Resources'))
                ->sort($resource::sort());
            Dashboard::registerMenuElement(\Orchid\Platform\Dashboard::MENU_MAIN, $title);
        }

        $menu = Menu::make($resource::label())
            ->icon($resource::icon())
            ->route('platform.resource.list', [$resource::uriKey()])
            ->active($this->activeMenu($resource))
            ->permission($resource::permission())
            ->sort($resource::sort());
        Dashboard::registerMenuElement(\Orchid\Platform\Dashboard::MENU_MAIN, $menu);
    });

    return $this;
}`

Edit pages

Hi any change edit page split two columns? example left col-md-9 and right col-md-3?

New resource not being rendered in the menu

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

ManyToMany relationships

Hey @tabuna :) I am keep working on and writing about Orchid CRUD. I was wandering, what about ManyToMany relationships?

Imagine I have two resources:

  1. Movie
  2. Genre

and I want to be able to define attach genres to a movie. How would you proceed? Is this something in the plans?

Thanks a lot for your precious time

Old value of Cropper on edit resource

Couldn't figure out how to get the old value of a custom attachment from certain model ,
i added the Attachable trait , and the attachments is working and i can get the default old values using Upload::value("attachment")

but i added a foreign key in my post model to set a default image ( featured image ) us the Cropper field but i can't preview it , apparently the Cropper::value() accepts the attachment url , and i couldn't link it to a relationship ( hasOne ) .

this is how i did resolve but it seems like a bad workaround :

PostResource

    private $post;

    public function __construct(Request $request)
    {
        $this->post =  (static::$model)::findOrFail($request->id);
    }
Cropper::make('featured_image')
                ->title('Featured  Image')
                ->width(500)
                ->height(300)
                ->horizontal()
                ->targetId()
                ->value( $this->post ? $this->post->featuredImage->url : true),

is there another way to do it?
should i add this change by default in the resource class to always get the model instance from the url param?

To be able to filter/search by foreign table's field

Hi,

I would like to propose being able to write code like below:

TD::make('payment_gateway_id', 'Payment Gateway')
    ->sort()
    ->query(function ($search, $builder) {
        return $builder
            ->select('customers.*') // required, otherwise sorting has issues
            ->join('payment_gateways', 'payment_gateways.id', '=', 'payment_gateway_id')
            ->where('payment_gateways.name', 'like', '%' . $search. '%');
    })
    ->render(function ($model) {
        return $model->payment_gateway->name;
    })

The purpose is so that we can search for a foreign table's field e.g. name instead of only being able to filter by ID as the user might not know the ID.

I was able to modify ResourceRequest.php with the code below,

    // update in ResourceRequest.php
    public function getModelPaginationList()
    {
        $builder = $this->model()
            ->with($this->resource()->with())
            ->filters()
            ->filtersApply($this->resource()->filters());

        foreach (collect($this->resource()->columns()) as $column) {
            $callback = $column->queryClosure; // also need to modify TD.php to support queryClosure
            if (!is_null($callback)) {
                $filters = $this->request->all('filter');
                $key = $column->column;
                if (Arr::exists($filters, $key)) {
                    $term = $filters[$key];
                    $builder = $callback($term, $builder);
                }
            }
        }

        return $builder->paginate($this->resource()->perPage());
    }

    // add to TD.php
    /**
     * @var Closure|null
     */
    public $queryClosure;

    public function query(Closure $queryClosure)
    {
        $this->queryClosure = $queryClosure;
        return $this;
    }

Is there a better approach to make searching by foreign table field easier?

Custom crud Screens.

how think about that to set screens in routes/crud.php by config file for full customization?

eg
config/platform-crud.php

return [
      'createScreen' => MyCustomCreateScreen::class,
      //list, edit, view...
];

"Resource" is indiscriminately removed from Resource title

Hi

I have my own Model type called "Resource", making the Orchid-Crud class "ResourceResource". The page title doesn't show though because the nameWithoutResource class strips the word "Resource" from everywhere in the class name, not just the end. I better solution would be replacing this line:

return Str::of(class_basename(static::class))->replace('Resource', '');

with something like (assuming they always end in "Resource"):
return substr(Str::of(class_basename(static::class)), 0, -8);

Laravel's resource naming convention difference

Hi,

Any reason why we don't follow Laravel's convention?
It becomes one more thing to learn. Also, the VERB is not "restricted" in Orchid/Crud

Reason I'm looking at this is because I'm trying to create a Download button in a column of each row.

Thank you.

Action Laravel Orchid/Crud
list GET /admin/crud/documents ANY admin/crud/list/documents
create GET /admin/crud/documents/create ANY admin/crud/create/documents
view GET /admin/crud/documents/{id} ANY admin/crud/view/documents/{id}
edit GET /admin/crud/documents/{id}/edit ANY admin/crud/edit/documents/{id}

https://laravel.com/docs/8.x/controllers#actions-handled-by-resource-controller

Hide default actions in ListScreen

Thanks for all the great work on this project!

Is there a way to hide the default View and Update actions on each record in the list view? Currently it seems like the only real way to override anything in the ListScreen is to create a full custom screen.

Add custom actions on rows

Hi,

I haven't find in the doc how to add a link to an other screen next to View and Edit buttons... So, is it possible ?

Thanks !

Resource 'screens' does not have the 'description' property

On a Screen, there is the name and description property that is displayed as a header.
When using a CRUD / Resource there is no possibility to set the description of the Screen.

The name property of the Screen is taken from the resource::label() in the constructor

Unable to run tests

Hi,

I added the following to phpunit.xml

        <server name="DB_CONNECTION" value="sqlite"/>
        <server name="DB_DATABASE" value=":memory:"/>

But I still get the errors when running tests

Action (Orchid\Crud\Tests\Action)
 ✘ Run action with empty resource  1034 ms
   ┐
   ├ Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: posts (SQL: insert into "posts" ("title", "description", "body", "updated_at", "created_at") values (Oh dear!., By the time at the mushroom for a good deal until she had tired herself out with trying, the poor., So she called softly after it, never once considering how in the window, I only knew how to speak again. The rabbit-hole went straight on like a serpent. She had already heard her sentence three of the treat. When the procession moved on, three of her ever getting out of a muchness"--did you ever eat a little bird as soon as she could, and soon found herself safe in a moment to think to herself, as usual. I wonder what was coming. It was all very well as she could. 'The game's going on rather., 2021-07-06 07:24:15, 2021-07-06 07:24:15))

I guess the tables were not created. Personally, I always have these 2 lines in my tests

    use \Illuminate\Foundation\Testing\DatabaseMigrations;
    use \Illuminate\Foundation\Testing\RefreshDatabase;

Any idea why the tables are not created? Thank you.

Resource menu item disappears when permission not granted for one resource

Hi,
First - thanks for the great software, this is saving SOOOO much time.

I've spotted an issue though: I have multiple resources defined, and if the current user has access to all resources, then the "Resources" top-level menu item appears.

But if any one of the resources is not permitted, then the top level Resource item disappears.

See screenshots:

without-permissions
with-permissions

The value of Button in form is being overwritten

I am trying to add a submit button at the end of the form.

public function fields(): array
    {
        return [
            // other fields ...
            Button::make($this::updateButtonLabel())
                ->class('btn btn-primary')->method('update')
        ];
    }

The button is being added and seems to be working.

But the problem is, the button value is being overwritten and becoming model[Update ResourceName].

CleanShot 2021-12-19 at 15 58 26@2x

How can I avoid this and keep the button name as is? Can anyone help?

Setting Value() on "select" fields that are called "active" doesn't work

Hey. I have the following code for creating a select field. However no matter what I do it always defaults the "disabled". However, as soon as I change then name from 'active' to anything else it works just fine. I haven't dug too far into the code but I suspect there's an attribute called 'active' that might be messing it up or something.
Thanks.

  Select::make('active')
      ->title('Status')
      ->options([
          'enabled'  => 'Enabled',
          'disabled' => 'Disabled',
      ])
      ->value('enabled'),

Filter causes ID to display wrongly

image

  1. I have 2 tables contacts and payments, related by payments.contact_id
  2. I wrote a QueryFilter.php for payments filtering by using contacts information
    public function run(Builder $builder): Builder
    {
        $searchTerm = $this->request->get('search');

        return $builder
            ->join('contacts', 'contacts.id', '=', 'payments.contact_id')
            ->where('contacts.surname', 'LIKE', '%' . $searchTerm . '%')
            ->orWhere('contacts.email', 'LIKE', '%' . $searchTerm . '%')
        ;
    }
  1. In my Payments.php resource, I had to do this:
    public function columns(): array
    {
        return [
            TD::make('id'),
        ...
    }

    public function filters(): array
    {
        return [
            \App\Orchid\Filters\PaymentsFilter::class,
            new DefaultSorted('payments.id', 'desc'),
        ];
    }
  1. Before filter is applied, both payments.id and contacts.id shows the correct values
  2. After filter is applied, payments.id shows the value of contacts.id
  3. Looks like a bug to me, any idea?

Thank you.

CRUD auto discovery for packages

Hi,

I would like to add lines 78 to 92 into the BootCrudGenerator.php middleware for auto discovery. See https://github.com/bilogic/OrchidExamples/blob/265e5ea2f72d42ddedc45877cae8e549d6cc94c5/src/OrchidExamplesServiceProvider.php#L78

This will allow packages to define namespace and folders that BootCrudGenerator.php should also search/discover for

app()->packageOrchidResources = ['Bilogic\\OrchidExamples' => __DIR__];

This already works on my system but I will be happy to make changes if there is a better way to do this. Thank you.

[4.0] Support of nested relations when viewing

It would be great to add a display of nested resources when browsing, for example:

image

In this regard, I propose to add a new method to the resource class responsible for this:

public function relations(): array
{
    return [
        Single('user', UserResource::class),
        Many('comments', CommentResource::class),
    ];
}

Where the first argument will be the name of the communication method in the model, that is:

class Post extends Model
{
    // ...

    public function user()
    {
        return $this->belongsTo(User::class, 'author');
    }

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}

And the second will be the name of the class in which you want to display the resulting models.

After returning from the 403 screen dropdowns don't work

I created a resource and policy. And set return false the create method. Navigate the resource list page. Click create button and navigate back. Then when u click your profile name you can see dropdown doesn't work. And there is also css problem after that.

{
  "require": {
    "laravel/framework": "^8.12",
    "orchid/crud": "^2.7",
    "orchid/platform": "^9.19"
  }
}

Chrome Version 88.0.4324.182 (Official Build) (64-bit)
Fedora 33

Screenshot from 2021-03-03 20-57-49

Image always with path localhost

I use a Cropper in my resource. It is working fine. Except the file path, when editing, who is not good.
It use http://localhost/storage/2021/10/18/c0d39298abcd2f0b65e3d583f475fef53bfc78ea.png and not the good APP_URL defined in the .env file.

I haven't changed anything in the filesystems.php

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

And platform.php

    'attachment' => [
        'disk'      => 'public',
        'generator' => \Orchid\Attachment\Engines\Generator::class,
    ],

Also php artisan cache:clear do not do anything.

Redirect handling after save

In some projects it is necessary to redirect back to the resource edit view after save instead of being redirected to the resource index view.

I imagine that a resource function for handling redirects after save action would be the optimal solution for this issue.

Seting custom attributes for validator errors failed

Setting Custom Validation Attributes in validation.php selected locale "ru" does not work for crud create form.
Setting Custom Validation Attributes in "attributes" method crud resource also doesn't work.

image

    /*
    |--------------------------------------------------------------------------
    | Custom Validation Attributes
    |--------------------------------------------------------------------------
    |
    | The following language lines are used to swap our attribute placeholder
    | with something more reader friendly such as "E-Mail Address" instead
    | of "email". This simply helps us make our message more expressive.
    |
    */

    'attributes' => [
        'title' => 'Название',
        'landing_page_link' => 'Ссылка на посадочную страницу',
        'recipient_list_file' => 'Файл определенного формата',
    ],
    /**
     * Get custom attributes for validator errors.
     *
     * @return array
     */
    public function attributes(): array
    {
        return [
            'title' => 'Название',
            'landing_page_link' => 'Ссылка на посадочную страницу',
            'recipient_list_file' => 'Файл определенного формата',
        ];
    }

Incorrect model passed to policy methods when listing resources

There seems to be an issue when using policies with listing resources.

For each item on the list, the corresponding policy's view() and edit() methods are invoked (as expected). However, the second argument passed to them is an empty model and not the actual item's model instance (ie, it does not have the item's attributes set).

It appears that this can be fixed with limited modifications. What do you think?

Active menu is not highlighting on list with pagination

on page /crud/list/task-resources resource menu item is highlighted.
on page /crud/list/task-resources?page=2 resource menu item is NOT highlighted.

the same behaviour with any query on resource list page, for example with using filter.

Create Resource Failed

I've installed crud 3.8 on Orchid 13.7.1 Laravel 9

`
$ php artisan orchid:resource CarsResource

ERROR Command "orchid:resource" is not defined. Did you mean one of these?
⇂ make:resource
⇂ orchid:admin
⇂ orchid:chart
⇂ orchid:filter
⇂ orchid:install
⇂ orchid:listener
⇂ orchid:presenter
⇂ orchid:publish
⇂ orchid:rows
⇂ orchid:screen
⇂ orchid:selection
⇂ orchid:tab-menu
⇂ orchid:table
`

Render image in Slight

Hi,

I am using the CRUD package but how to render image here:

Sight::make('image'); (this is just a text)

I tried:

Sight::make('image')->render(function (){
return Picture::make('image');
}),

but it returned an error and also I didn't found any solution in the documentation, can you help here?

Query Builder for model

Is there any way I can use Query Builder on the model to only retrieve selected rows?

Or maybe this can also be achieved using Policy view() method.

Access authenticated user to fill resource foreign key

I'm trying to add a post management with resources, but I didn't understand how to get the current user ID from my PostResource itself.
I saw that there is a onSave method, but there is nothing about getting the user ID from resources objects.

My post object has a foreign key to user.id named user_id and I would like to fill it when I create a new post. How can I do that ?

textNotFound for resources?

Hi,
I'd like to change the text "There are no records in this view" for each resource I've set up. I thought you would be able to do it like this::

class TimerResource extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = \App\Models\Timer::class;

    /**
     * @return string
     */
    protected function textNotFound(): string
    {
        return __('There are no timers');
    }

    ...

But that's not working.

Anyone know how to do this?

Regards,
Andy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.