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

Add make:table command #408

Merged
merged 5 commits into from
Aug 1, 2021
Merged

Add make:table command #408

merged 5 commits into from
Aug 1, 2021

Conversation

iAmKevinMcKee
Copy link
Contributor

I've added the make:table command. You just pass a class name and it scaffolds out a stub that helps you get started.

Hopefully this is pretty self explanatory. I used a lot of the code and approach as the Livewire make command.

Sorry I don't have any tests.

@bomshteyn
Copy link
Contributor

This is great idea.
I think though make:table is very generic and should be a bit more specific.

@iAmKevinMcKee
Copy link
Contributor Author

This is great idea.
I think though make:table is very generic and should be a bit more specific.

The maintainer requested this as the command. It doesn't conflict with anything else. #399 (comment)

@rappasoft
Copy link
Owner

Probably a valid point though I can't imagine people installing two table plugins in one project?

@iAmKevinMcKee
Copy link
Contributor Author

A really simple upgrade to this would be to pass in an optional parameter for the model you are working with, and have that prepopulate in the query() method.

For example, php artisan make:table UsersTable --model=User would also add this:

public function query(): Builder
{
    return User::query(); // this line here
}

It could be simplified even more by just accepting the model name as the second parameter, so

php artisan make:table UsersTable User

Happy to add this if you like.

@iAmKevinMcKee
Copy link
Contributor Author

Okay, I added the model as a second parameter (optional). Now you can do this:

scaffold without the model
php artisan make:model UsersTable

scaffold with User model
php artisan make:model UsersTable User

I built the logic to be smart enough to import the model class as long as the model is either in the app folder or in the app/models folder. If it's somewhere else, then I show an error in the console and just import the non-existent app/models file.

@rappasoft
Copy link
Owner

Awesome good work. I'll try to get this in this week I've just been swamped.

@iAmKevinMcKee
Copy link
Contributor Author

I added one more feature. If you pass in --view or -V then the command will generate a row view for you in resources/views/livewire-tables/rows/ with the following stub:

<x-livewire-tables::table.cell>
{{--    Note: This is a tailwind cell    --}}
{{--    For bootstrap 4, use <x-livewire-tables::bs4.table.cell>    --}}
{{--    For bootstrap 5, use <x-livewire-tables::bs5.table.cell>    --}}
</x-livewire-tables::table.cell>

and it will also add the row view method to the class:

public function rowView(): string
{
    return 'livewire-tables/rows/snake_of_classname.blade.php';
}

@iAmKevinMcKee
Copy link
Contributor Author

Sorry for all the commits. I'm just now getting into some good testing and I'm finding issues. I think I have worked everything out now. Feel free to squash commits.

@lloricode
Copy link
Contributor

This is great idea.
I think though make:table is very generic and should be a bit more specific.

yes, it will become confusing on large projects

@iAmKevinMcKee
Copy link
Contributor Author

Just checking in here. Anything else you'd like me to consider adding or anything I can explain?

@rappasoft
Copy link
Owner

Just checking in here. Anything else you'd like me to consider adding or anything I can explain?

Sorry I've been swamped. I'm looking at it now (though its 1am here) and will probably finish looking tomorrow. I'm going to change it to make:datatable just in case we conflict with something else.

I'll make a release even if this is the only thing just so people can use it.

@rappasoft rappasoft added the Awaiting Next Release Currently merged into development awaiting a release to master label Jul 31, 2021
@rappasoft rappasoft mentioned this pull request Aug 1, 2021
@rappasoft rappasoft merged commit 48c5d5f into rappasoft:master Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Next Release Currently merged into development awaiting a release to master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants