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 documentation for condition in splade table #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion automatic-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/10.x/vite#running-vite), you may run the Vite development server:

### npm

```bash
npm run dev
````
```

### yarn

```bash
yarn dev
```
10 changes: 9 additions & 1 deletion breeze.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/10.x/vite#running-vite), you may run the Vite development server:

### npm

```bash
npm run dev
````
```

### yarn

```bash
yarn dev
```
26 changes: 19 additions & 7 deletions manual-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -104,4 +116,4 @@ Splade assumes the path of this file is `resources/views/root.blade.php`. If you

```php
Splade::setRootView('base-layout');
```
```
56 changes: 55 additions & 1 deletion table-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -171,4 +225,4 @@ You may use the `columns()` method and `resource` property of the table instance
</x-splade-table>
```

Also, check out the [default Blade templates](https://github.com/protonemedia/laravel-splade/tree/main/resources/views/table) for other related features.
Also, check out the [default Blade templates](https://github.com/protonemedia/laravel-splade/tree/main/resources/views/table) for other related features.