From ccf199a6b741ffe0ed71c3ab50c9923937833205 Mon Sep 17 00:00:00 2001 From: Zulfikar Ditya <52193940+zulfikar-ditya@users.noreply.github.com> Date: Tue, 14 Feb 2023 17:56:29 +0700 Subject: [PATCH 1/3] adding documentation for condition in splade table --- table-overview.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/table-overview.md b/table-overview.md index b26b630..8aedc08 100644 --- a/table-overview.md +++ b/table-overview.md @@ -107,6 +107,60 @@ public function authorize(Request $request) Instead of always returning `true`, you may also remove the method if you don't want to use authorization. +## Conditional in splade table +Sometimes we need some ```condition``` in our data table. splade have build in conditional in splade data table. + +```php +SpladeTable::for(User::class) + ->column('name') + ->when(Auth::user()->is_admin, function ($table) { + $table->column('email'); + }) + ->paginate(15); +``` + +You can also using inline function in php. +```php +SpladeTable::for(User::class) + ->column('name') + ->when(Auth::user()->is_admin, fn ($table) => $table->column('email')) + ->paginate(15); +``` + +You maybe need with ```Laravel-permission``` from spatie. here is the example. +```php +SpladeTable::for(User::class) + ->column('name') + ->when(Auth::user()->hasPermission("delete user"), function ($table) { + $table->bulkAction( + label: 'Delete data', + each: fn (User $user) => $user->delete(), + confirm: 'Delete users', + confirmText: 'Are you sure you want to delete the users?', + confirmButton: 'Yes, delete all selected rows!', + cancelButton: 'No, do not delete!', + ); + }) + ->paginate(15); +``` + +You can also using splade table class. +```php +// ... +$table->column('name') + ->when(Auth::user()->hasPermission("delete user"), function ($table) { + $table->bulkAction( + label: 'Delete data', + each: fn (User $user) => $user->delete(), + confirm: 'Delete users', + confirmText: 'Are you sure you want to delete the users?', + confirmButton: 'Yes, delete all selected rows!', + cancelButton: 'No, do not delete!', + ); + }); +// ... +``` + ## Pagination When the dataset is paginated, it will, by default, show a select dropdown to customize the number of rows per page. In addition, you may define a custom set of options using the `perPageOptions` method on the `SpladeTable`: @@ -159,4 +213,4 @@ You may use the `columns()` method and `resource` property of the table instance ``` -Also, check out the [default Blade templates](https://github.com/protonemedia/laravel-splade/tree/main/resources/views/table) for other related features. \ No newline at end of file +Also, check out the [default Blade templates](https://github.com/protonemedia/laravel-splade/tree/main/resources/views/table) for other related features. From 2bd20fd36c5d62a2b2a7bc4db7506554f29d44be Mon Sep 17 00:00:00 2001 From: Zulfikar Ditya Date: Tue, 14 Feb 2023 18:06:42 +0700 Subject: [PATCH 2/3] instalation using yarn --- automatic-installation.md | 10 +++++++++- breeze.md | 10 +++++++++- manual-installation.md | 26 +++++++++++++++++++------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/automatic-installation.md b/automatic-installation.md index ec81951..01121c3 100644 --- a/automatic-installation.md +++ b/automatic-installation.md @@ -14,6 +14,14 @@ php artisan splade:install The `splade:install` command will also build the frontend assets. Just like [regular Laravel applications](https://laravel.com/docs/9.x/vite#running-vite), you may run the Vite development server: +### npm + ```bash npm run dev -```` \ No newline at end of file +``` + +### yarn + +```bash +yarn dev +``` diff --git a/breeze.md b/breeze.md index 3b4ecfd..f6ea3db 100644 --- a/breeze.md +++ b/breeze.md @@ -16,6 +16,14 @@ php artisan breeze:install The `breeze:install` command will also build the frontend assets. Just like [regular Laravel applications](https://laravel.com/docs/9.x/vite#running-vite), you may run the Vite development server: +### npm + ```bash npm run dev -```` \ No newline at end of file +``` + +### yarn + +```bash +yarn dev +``` diff --git a/manual-installation.md b/manual-installation.md index 7527a5e..26a7f0e 100644 --- a/manual-installation.md +++ b/manual-installation.md @@ -50,10 +50,22 @@ class Handler extends ExceptionHandler On the frontend, you must ensure [Tailwind CSS 3.0](https://tailwindcss.com) and [Vue 3.0](https://vuejs.org) are correctly configured. Then, install the Splade frontend package: +### npm + +Via npm + ```bash npm install @protonemedia/laravel-splade ``` +### yarn + +Via yarn + +```bash +yarn add @protonemedia/laravel-splade +``` + In your Tailwind configuration file, make sure you add the Splade package to the content array: ```js @@ -69,21 +81,21 @@ module.exports = { }; ``` -In the `createApp` section of your main JavaScript file, you need to use the Splade plugin, as well as the custom render method. Note how it imports the `createApp` method from the *bundler* Vue build, as that build includes the [Vue template compiler](https://vuejs.org/guide/scaling-up/tooling.html#note-on-in-browser-template-compilation). +In the `createApp` section of your main JavaScript file, you need to use the Splade plugin, as well as the custom render method. Note how it imports the `createApp` method from the _bundler_ Vue build, as that build includes the [Vue template compiler](https://vuejs.org/guide/scaling-up/tooling.html#note-on-in-browser-template-compilation). ```js import "@protonemedia/laravel-splade/dist/style.css"; import { createApp } from "vue/dist/vue.esm-bundler.js"; -import { renderSpladeApp, SpladePlugin } from '@protonemedia/laravel-splade' +import { renderSpladeApp, SpladePlugin } from "@protonemedia/laravel-splade"; -const el = document.getElementById('app') +const el = document.getElementById("app"); createApp({ - render: renderSpladeApp({ el }) + render: renderSpladeApp({ el }), }) - .use(SpladePlugin) - .mount(el); + .use(SpladePlugin) + .mount(el); ``` As you can see at the top, there's also a default stylesheet to support the Choices.js, FilePond, and Flatpickr integrations of the [Form Components](/form-overview.md). Though you probably want to import this default stylesheet into your main JavaScript file, it's completely optional. @@ -104,4 +116,4 @@ Splade assumes the path of this file is `resources/views/root.blade.php`. If you ```php Splade::setRootView('base-layout'); -``` \ No newline at end of file +``` From 2d6dcccc56a4c1067bda255520abe8af1fcbcf62 Mon Sep 17 00:00:00 2001 From: Zulfikar Ditya <52193940+zulfikar-ditya@users.noreply.github.com> Date: Wed, 26 Apr 2023 11:59:34 +0700 Subject: [PATCH 3/3] adding before and after docs in splade bulk action --- table-bulk-actions.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/table-bulk-actions.md b/table-bulk-actions.md index d46af75..ba3bdd2 100644 --- a/table-bulk-actions.md +++ b/table-bulk-actions.md @@ -119,3 +119,19 @@ class Projects extends AbstractTable } } ``` + +## Getting all selected data +Maybe somtime we want to get all selected data in splade bulk action. It's posible to get all ids or selected data using method `before` or `after` from splade table. Here is the example: + +```php +$table->bulkAction( + label: 'Notify users', + before: function (array $selectedIds) { + $users = User::query() + ->unless($selectedIds === ['*'], fn ($query) => $query->whereIn('id', $selectedIds)) + ->get(); + + Mail::to($users)->send(new ImportantNotification); + } +); +```