Skip to content

Commit bf20c79

Browse files
authored
Merge pull request #123 from Gustavinho/release/2.3.0
Release/2.3.0
2 parents 270040f + fd0a9f0 commit bf20c79

File tree

105 files changed

+1613
-1098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1613
-1098
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ branches:
2626
- dev
2727
- /^release-.*$/
2828
- /^release/.*$/
29+
- /^feature/.*$/
2930

3031
before_script:
3132
- composer config discard-changes true

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"bladeFormatter.format.indentSize": 2,
3+
"bladeFormatter.format.wrapAttributes": "force"
4+
}

README.md

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Laravel package to create beautiful common views like tables using only PHP code
99
![](doc/laravel-views.png)
1010

1111
- [Version compatibility](#version-compatibility)
12+
- [Upgrade guide](#upgrade-guide)
1213
- [Installation and basic usage](#installation-and-basic-usage)
1314
- [Installing laravel views](#installing-laravel-views)
1415
- [Publishing assets](#publishing-assets)
@@ -26,10 +27,10 @@ Laravel package to create beautiful common views like tables using only PHP code
2627
- [Roadmap](#roadmap)
2728

2829
# Version compatibility
29-
|Laravel views|Livewire|Laravel|
30-
|-|-|-|
31-
|2.x|2.x|7.x, 8.x|
32-
|1.x|1.x|5.x, 6.x|
30+
|Laravel views|Alpine|Livewire|Laravel|
31+
|-|-|-|-|
32+
|2.x|2.8.x, 3.x.x|2.x|7.x, 8.x|
33+
|1.x|2.8.x|1.x|5.x, 6.x|
3334

3435
# Installation and basic usage
3536

@@ -59,12 +60,13 @@ Add the following Blade directives in the *head* tag, and before the end *body*
5960
</html>
6061
```
6162

62-
These blade directives are also including [Laravel livewire](https://laravel-livewire.com/) and [Tailwindcss](https://tailwindcss.com/) styles and scripts, after that you may need to clear the view cache
63+
Laravel Views includes by default a set up using different parts of the TALL stack assets like the [Laravel livewire](https://laravel-livewire.com/) and [Tailwindcss](https://tailwindcss.com/) styles and scripts, it alsoincludes the [Alpine.js](https://laravel-livewire.com/docs/2.x/alpine-js) script, after adding these directives you may need to clear the view cache
64+
6365
```bash
6466
php artisan view:clear
6567
```
66-
If you are already using your own Tailwindcss setup you can set `laravel-views` to not importing Tailwindcss by default. ([Importing assets](./doc/laravel-views#including-assets))
6768

69+
These directives are fine for a dev environment, however, if you want to use your own Tailwindcss or Alpinde.js setup, you can [disable these assets](./doc/laravel-views#including-assets) from being loaded with the Laravel views directive.
6870
# First table view
6971
This is a basic usage of a table view, you can [read the full table view documentation ](doc/table-view.md)
7072

@@ -75,7 +77,7 @@ php artisan make:table-view UsersTableView
7577
```
7678
With this artisan command a UsersTableView.php file will be created inside the `app/Http/Livewire` directory.
7779

78-
The basic usage needs a data repository (Eloquent query), headers and rows, you can customize the items to be shown, and the headers and data for each row like this example
80+
The basic usage needs a model class, headers and rows, you can customize the items to be shown, and the headers and data for each row like this example
7981
```php
8082
<?php
8183

@@ -87,10 +89,7 @@ use App\User;
8789

8890
class UsersTableView extends TableView
8991
{
90-
public function repository(): Builder
91-
{
92-
return User::query();
93-
}
92+
protected $model = User::class;
9493

9594
public function headers(): array
9695
{
@@ -128,7 +127,7 @@ You could also use the `@livewire` blade directive.
128127

129128
At this point, you would be able to see a table with some data, the table view doesn't have any styled container or title as the image example, you can render the table view inside any container you want.
130129

131-
In the example above the view is using the User model created by default in every Laravel project, feel free to use any model you have, the method `row` is receiving a sinlge model object and you can use any property or public method you have difined inside your model.
130+
In the example above the view is using the User model created by default in every Laravel project, feel free to use any model you want, the method `row` is receiving a sinlge model object and you can use any property or public method you have difined inside your model.
132131

133132
This is the basic usage of the table view, but you can customize it with more features.
134133

@@ -177,4 +176,57 @@ Here's the plan for what's coming:
177176
- Add tooltips to actions buttons
178177
- Add a download action
179178
- Add translations
180-
- Add links as a UI helpers
179+
- Add links as a UI helpers
180+
181+
## Upgrade guide
182+
### From 2.2 to 2.3
183+
**Cached views**
184+
185+
The blade directives have changed, you need to clear the cached views with `php artisan view:clear`
186+
187+
**Public assets**
188+
189+
The main assets (JS and CSS files) have changed, you need to publish the public assets again with `php artisan vendor:publish --tag=public --provider='LaravelViews\LaravelViewsServiceProvider' --force`
190+
191+
**Publish blade componentes**
192+
193+
Some of the internal components have changed, if you have published these components before to customize them, you will not have them up to date, unfourtunately you need to publish them again with `php artisan vendor:publish --tag=views --provider='LaravelViews\LaravelViewsServiceProvider'` and customize them as you need.
194+
195+
**Method `renderIf()` in actions**
196+
197+
Update the renderIf() function in your action classes adding a new `$view` parameter as follows:
198+
```php
199+
<?php
200+
201+
namespace App\Actions;
202+
203+
use LaravelViews\Actions\Action;
204+
use LaravelViews\Views\View; // new line
205+
206+
class YourAction extends Action
207+
{
208+
public function renderIf($item, View $view) // add the view parameter
209+
{
210+
// your content
211+
}
212+
}
213+
```
214+
**Publish config file (Optional)**
215+
216+
Some new variants have been added to the config file, if you have published the config file before, you could publish it again so you can customize the new variants, this doesn't affect anything at all since the new variants will be taken from the default config file.
217+
218+
**Remove `repository` method from your views (Optional)**
219+
220+
If your `repository()` methods are returning a query object without any other query applied like `User::query()`, you can define a `protected $model = User::class;` instead, this is the default behavior now, the `repository()` method is still working so you don't need to change anything if you don't want to.
221+
222+
```php
223+
/* Before */
224+
public function repository(): Builder
225+
{
226+
// You are using a single query
227+
return User::query();
228+
}
229+
230+
/** After */
231+
protected $model = User::class;
232+
```

doc/grid-view.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This view creates a dynamic grid view using card data, same as a TableView this
1010
- [Defining initial data](#defining-initial-data)
1111
- [Defining card data](#defining-card-data)
1212
- [Customizing card data](#customizing-card-data)
13+
- [Default card item action](#default-card-item-action)
14+
- [Sorting Data](#sorting-data)
1315
- [More features](#more-features)
1416
- [Searching data](./table-view.md#searching-data)
1517
- [Pagination](./table-view.md#pagination)
@@ -30,17 +32,33 @@ With this artisan command a `ExampleGridView.php` file will be created inside `a
3032

3133
## Defining initial data
3234

33-
Return an `Eloquent` query with the initial data to be displayed on the grid view, it is important to return the query, not the data collection.
35+
The GridView class needs a model class to get the initial data to be displayed on the table, you can define it in the `$model` property.
3436

3537
```php
3638
use App\User;
3739

40+
protected $model = User::class;
41+
```
42+
43+
If you need an specific query as initial data you can define a `repository` method returning an `Eloquent` query with the initial data to be displayed on the grid view, it is important to return the query, not the data collection.
44+
45+
```php
46+
use App\User;
47+
use Illuminate\Database\Eloquent\Builder;
48+
49+
/**
50+
* Sets a initial query with the data to fill the table
51+
*
52+
* @return Builder Eloquent query
53+
*/
3854
public function repository(): Builder
3955
{
4056
return User::query();
4157
}
4258
```
4359

60+
If you define this method, the `$model` property is not needed anymore.
61+
4462
## Defining card data
4563

4664
You have to define a public function returning an array with the data that will be displayed on each card, this array has to include `photo`, `title`, `subtitle` and the `description`.
@@ -61,10 +79,45 @@ These are the fields by default but you can add more if you want to customize yo
6179

6280
## Customizing card data
6381

64-
The grid view has a card component by default with some data but you can either create your own card and use as much data as you need in the `card` mthod and just use your own card implementation, you just need to specify a blade file.
82+
The grid view has a card component by default with some data, however, you can create your own card component and use as much data as you need in the `card` method, you just need to specify a blade file with your Grid View and return the data that you need in the `card` method.
6583

6684
```php
6785
public $cardComponent = 'components.my-card';
86+
87+
public function card($model) {
88+
return [
89+
'name' => $model->name,
90+
'email' => $model->email,
91+
'model' => $model
92+
];
93+
}
94+
```
95+
96+
All the data returned in the `card` method will be received as a prop in your blade component alog with these other default props that you can use based on your needs.
97+
98+
Name|Description|Type|Value
99+
--|--|--|--|
100+
model|Model instance for this card|||
101+
actions|Actions defined in this view class|Array
102+
hasDefaultAction|Checks if the Grid View has defined a `onCardClick` method|Boolean|true,false
103+
selected|Defines if the item was selected when the grid view has bulk actions|Boolean|true,false
104+
105+
With all this data you can build your own card component as you need, remember to include an `actions` component.
106+
107+
```html
108+
<x-lv-actions :actions="$actions" :model="$model" />
109+
<!-- Or -->
110+
<x-lv-actions.drop-down :actions="$actions" :model="$model" />
111+
```
112+
113+
114+
## Default card item action
115+
You can define a default action that will be fired clicking on the card image or the card title, this action gets the model instance that fired it.
116+
117+
```php
118+
public function onCardClick(User $model)
119+
{
120+
}
68121
```
69122

70123
## Max columns
@@ -84,6 +137,19 @@ public $withBackground = true
84137

85138
This will render the item with a white background.
86139

140+
## Sorting data
141+
You can add an option to sort the items on the grid view by an specific field defining a `sortableBy` method with an array of the fields to sort by, as the grid view desn't have headers, a `Sort by` button will be displayed with a drop down with all the fields defined in this method.
142+
143+
```php
144+
public function sortableBy()
145+
{
146+
return [
147+
'Name' => 'name',
148+
'Email' => 'email'
149+
];
150+
}
151+
```
152+
87153
## More features
88154
This grid view is based on a table view, so you could use some of the table view features as:
89155

doc/laravel-views.md

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
- [Grid view](doc/grid-view.md)
2222

2323
# Version compatibility
24-
|Laravel views|Livewire|Laravel|
25-
|-|-|-|
26-
|2.x|2.x|7.x, 8.x|
27-
|1.x|1.x|5.x, 6.x|
24+
|Laravel views|Alpine|Livewire|Laravel|
25+
|-|-|-|-|
26+
|2.x|2.8.x, 3.x.x|2.x|7.x, 8.x|
27+
|1.x|2.8.x, 3.x.x|1.x|5.x, 6.x|
2828

2929
# Installation and basic usage
3030

@@ -69,24 +69,26 @@ You can specify which assets you want to include passing a string to those direc
6969

7070
```php
7171
@laravelViewsStyles(laravel-views,tailwindcss,livewire)
72+
@laravelViewsScripts(laravel-views,livewire,alpine)
7273
```
7374

74-
If you dont need to include `Tailwindcss` or `Livewire` assets you can just set the `laravel-views` assets in the list.
75+
If you dont need to include `Tailwindcss`, `Livewire` or `Alpine` assets you can just set the `laravel-views` assets in the list.
7576

7677
```php
7778
@laravelViewsStyles(laravel-views)
79+
@laravelViewsScripts(laravel-views)
7880
```
7981

82+
This is recomended for a production environment where you surely have a compile assets pipeline, like Laravel Mix, or you want to include the assets from a CDN on your own.
83+
8084
## Purge Tailwindcss styles
8185
If you're using your own Tailwindcss setup you must consider `laravel-views` in your `purge` configuration, for that just add this path to the `purge` array on the `tailwind.config.js`file.
8286

8387
```js
84-
purge: {
85-
content: [
86-
//...Rest of your paths
87-
"./vendor/laravel-views/**/*.php",
88-
],
89-
},
88+
purge: [
89+
//...Rest of your paths
90+
"./vendor/laravel-views/**/*.php",
91+
],
9092
```
9193

9294
# First table view
@@ -147,63 +149,11 @@ In the example above the view is using the User model created by default in ever
147149
This is the basic usage of the table view, but you can customize it with more features.
148150

149151
[Read the full table view documentation ](doc/table-view.md)
150-
151-
# Rendering a view from a controller
152-
153-
You can render a view manually in a controller creating a `LaravelViews` instance and executing the `render` method on a `blade` file.
154-
155-
```php
156-
use use LaravelViews\LaravelViews;
157-
158-
public function index(LaravelViews $laravelViews)
159-
{
160-
$laravelViews->create(App\Http\Livewire\UsersTableView::class);
161-
162-
return view('my-view', [
163-
'view' => $laravelViews
164-
]);
165-
}
166-
```
167-
And render it in your blade file
168-
```blade
169-
{!! $view->render() !!}
170-
```
171-
172-
## Specifying a layout and section
173-
You can also return the view directly from your controller and specify the layout and section of your layout
174-
```php
175-
use use LaravelViews\LaravelViews;
176-
177-
public function index(LaravelViews $laravelViews)
178-
{
179-
$laravelViews->create(App\Http\Livewire\UsersTableView::class)
180-
->layout('layout', 'section-name');
181-
182-
return $laravelViews->render();
183-
}
184-
```
185-
186-
## Send extra data to the layout
187-
In the same way that you would send data to your views, you can send more data to the layout file
188-
```php
189-
use use LaravelViews\LaravelViews;
190-
191-
public function index(LaravelViews $laravelViews)
192-
{
193-
$laravelViews->create(App\Http\Livewire\UsersTableView::class)
194-
->layout('layout', 'section-name', [
195-
'title' => 'My layout title'
196-
]);
197-
198-
return $laravelViews->render();
199-
}
200-
```
201-
202152
# Components customization
203153
These views are build with [Tailwind CSS](https://tailwindcss.com/) and you can either change the colors of the components following tailwindcss utilities or fully customize all the html of the components
204154

205155
## Component variants using tailwindcss
206-
If you are using [Tailwind CSS](https://tailwindcss.com/) or if you don't have issues using Tailwindcss and your own css styles, you can customize some utilities to change the color for each variant of the components publishing a config file
156+
You can customize some of the components styles (like the color) for each one of the variants with a config file.
207157

208158
```bash
209159
php artisan vendor:publish --tag=config

0 commit comments

Comments
 (0)