|
1 | 1 | # Laravel views |
2 | 2 |
|
3 | | -[See live example](https://laravelviews.com) |
4 | | - |
5 | | -Laravel package to create beautiful common views like tables using only PHP code, inspired by [Laravel Nova](https://nova.laravel.com/), these views are built with [Laravel Livewire](https://laravel-livewire.com/) and styled using [Tailwind CSS](https://tailwindcss.com/) |
6 | | - |
7 | | -## Table View example |
8 | | - |
9 | | - |
10 | | - |
11 | | -- [Version compatibility](#version-compatibility) |
12 | | -- [Upgrade guide](#upgrade-guide) |
13 | | -- [Installation and basic usage](#installation-and-basic-usage) |
14 | | - - [Installing laravel views](#installing-laravel-views) |
15 | | - - [Publishing assets](#publishing-assets) |
16 | | - - [Including assets](#including-assets) |
17 | | -- [First table view](#first-table-view) |
18 | | - - [Rendering the table view](#rendering-the-table-view) |
19 | | -- [Rendering a view](#rendering-a-view) |
20 | | -- [Advanced usage](doc/laravel-views.md) |
21 | | -- [Views available](#views-available) |
22 | | - - [Table view](#table-view) |
23 | | - - [Grid view](#grid-view) |
24 | | - - [List view](#list-view) |
25 | | - - [Detail view](#detail-view) |
26 | | -- [Contributing](#contributing) |
27 | | -- [Roadmap](#roadmap) |
28 | | - |
29 | | -# Version compatibility |
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| |
34 | | - |
35 | | -# Installation and basic usage |
36 | | - |
37 | | -## Installing laravel views |
38 | | -```bash |
39 | | -composer require laravel-views/laravel-views |
40 | | -``` |
41 | | - |
42 | | -## Publishing assets |
43 | | -```bash |
44 | | -php artisan vendor:publish --tag=public --provider='LaravelViews\LaravelViewsServiceProvider' --force |
45 | | -``` |
46 | | - |
47 | | -## Including assets |
48 | | -Add the following Blade directives in the *head* tag, and before the end *body* tag in your template |
49 | | - |
50 | | -```blade |
51 | | -<html> |
52 | | -<head> |
53 | | - ... |
54 | | - @laravelViewsStyles |
55 | | -</head> |
56 | | -<body> |
57 | | - ... |
58 | | - @laravelViewsScripts |
59 | | -</body> |
60 | | -</html> |
61 | | -``` |
62 | | - |
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 | | - |
65 | | -```bash |
66 | | -php artisan view:clear |
67 | | -``` |
68 | | - |
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.md#including-assets) from being loaded with the Laravel views directive. |
70 | | -# First table view |
71 | | -This is a basic usage of a table view, you can [read the full table view documentation ](doc/table-view.md) |
72 | | - |
73 | | - |
74 | | -Once you have installed the package and included the assets you can start to create a basic table view. |
75 | | -```bash |
76 | | -php artisan make:table-view UsersTableView |
77 | | -``` |
78 | | -With this artisan command a UsersTableView.php file will be created inside the `app/Http/Livewire` directory. |
79 | | - |
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 |
81 | | -```php |
82 | | -<?php |
83 | | - |
84 | | -namespace App\Http\Livewire; |
85 | | - |
86 | | -use LaravelViews\Views\TableView; |
87 | | -use Illuminate\Database\Eloquent\Builder; |
88 | | -use App\User; |
89 | | - |
90 | | -class UsersTableView extends TableView |
91 | | -{ |
92 | | - protected $model = User::class; |
93 | | - |
94 | | - public function headers(): array |
95 | | - { |
96 | | - return [ |
97 | | - 'Name', |
98 | | - 'Email', |
99 | | - 'Created', |
100 | | - 'Updated' |
101 | | - ]; |
102 | | - } |
103 | | - |
104 | | - public function row($model) |
105 | | - { |
106 | | - return [ |
107 | | - $model->name, |
108 | | - $model->email, |
109 | | - $model->created_at, |
110 | | - $model->updated_at |
111 | | - ]; |
112 | | - } |
113 | | -} |
114 | | -``` |
115 | | - |
116 | | -## Rendering the table view |
117 | | -You can render this view in the same way as you would do it for a livewire component ([Rendering components](https://laravel-livewire.com/docs/2.x/rendering-components)). |
118 | | -The easiest way to render the view is using the livewire tag syntax: |
119 | | -```blade |
120 | | -<livewire:users-table-view /> |
121 | | -``` |
122 | | - |
123 | | -You could also use the `@livewire` blade directive. |
124 | | -```blade |
125 | | -@livewire('users-table-view') |
126 | | -``` |
127 | | - |
128 | | -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. |
129 | | - |
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. |
131 | | - |
132 | | -This is the basic usage of the table view, but you can customize it with more features. |
133 | | - |
134 | | -[Read the full table view documentation ](doc/table-view.md) |
135 | | - |
136 | | -## Advanced usage |
137 | | - |
138 | | -[Read the advanced laravel-views documentation ](doc/laravel-views.md) |
139 | | - |
140 | | -## Views available |
141 | | -### [Table view](doc/table-view.md) |
142 | | - |
143 | | -Dynamic data table with some features like filters, pagination and search input, you can customize the headers, the data to be displayed for each row |
144 | | - |
145 | | - |
146 | | - |
147 | | -### [Grid view](doc/grid-view.md) |
148 | | - |
149 | | -Dynamic grid view using card data, same as a TableView this view has features like filters, pagination and a search input, you can also customize the card data as you need |
150 | | - |
151 | | - |
152 | | - |
153 | | -### [List view](doc/list-view.md) |
154 | | - |
155 | | -Dynamic list view with filters, pagination, search input, and actions by each item, it is useful for small screens, you can also customize the item compoment for each row as you need. |
156 | | - |
157 | | - |
| 3 | + |
158 | 4 |
|
159 | | -### [Detail view](doc/detail-view.md) |
160 | | -Dynamic detail view to render a model attributes list with all the data you need, you can also customize the default component to create complex detail views and execute actions over the model is being used. |
| 5 | +Laravel package to create beautiful common views like data tables using the [TALL stack](https://tallstack.dev/). |
161 | 6 |
|
162 | | - |
| 7 | +- [Read the full documentation](https://laravelviews.com) |
| 8 | +- [See live examples](https://laravelviews.com/examples/table-view) |
163 | 9 |
|
164 | 10 | ## Contributing |
165 | 11 |
|
|
0 commit comments