Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding constructor to class for Datatable requires a Name #109

Closed
juliancarstairs opened this issue Aug 10, 2023 · 3 comments
Closed

Adding constructor to class for Datatable requires a Name #109

juliancarstairs opened this issue Aug 10, 2023 · 3 comments

Comments

@juliancarstairs
Copy link

I have a generic class taken from the skeleton example on docs

If I add a constructor to it so an example:

namespace App\Datatables\Users;

use Flavorly\VanillaComponents\Datatables\Datatable;
use Flavorly\VanillaComponents\Datatables\Options\General\Options;

class User extends Datatable
{
   public function __construct($id)
    {
        $this->id = $id;
    {
    public function query(): mixed
    {
        return User::query()->where('user_id', $this->id);
        
        // You can also return a closure or a relationship here
        // return fn() => User::query()->where('user_id', auth()->id());
        // Auth::user()->payments();
    }
    
    public function fetchEndpoint(): ?string
    {
        // Endpoint where the datatable will fetch the data from
        return route('datatables.demo');
    }
    
    public function columns(): array
    {
        return [
           // Columns go here
        ];
    }

    public function filters(): array
    {
        return [
            // Filters go here
        ];
    }

    public function actions(): array
    {
        return [
            // Actions go here
        ];
    }

    public function options(): array| Options
    {
        return Options::make()->refreshable()->hideSearchBar();
    }
}

I get the following error. I tried also defining the Name attribute on the class but that did not seem to work either.

Flavorly\VanillaComponents\Datatables\Datatable::getName(): Return value must be of type string, null returned

@juliancarstairs juliancarstairs changed the title Adding constructor to class for Datatable requires a Adding constructor to class for Datatable requires a Name Aug 10, 2023
@juliancarstairs
Copy link
Author

I have used parent::setup() after my declaration and seems to fix it, is this the correct way of going about things?

@nikuscs
Copy link
Collaborator

nikuscs commented Aug 10, 2023

All Datatables should implement a getName() name, maybe i forgot to mention on the docs, this is because filters and other stuff are prefixed by the name, so in case you want to have 2 datatables on same page, they would still work normally.

@juliancarstairs
Copy link
Author

I think you could implement an interface to ensure that this property is available on all Datatables, currently it uses the reflection class to set get name. just a thought. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants