You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: quick-starter.md
+68-68Lines changed: 68 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,66 +1,62 @@
1
-
# DataTables Quick Starter
1
+
# Quick Starter
2
2
3
-
## Create a new Laravel project
3
+
<aname="installation"></a>
4
+
## <b>01.</b> Installing Laravel & DataTables
4
5
5
-
```
6
+
### Quick Installation
7
+
8
+
If you have already installed [Laravel Installer](https://laravel.com/docs#your-first-laravel-project) on your local machine, you may create a new project via laravel command:
9
+
10
+
```shell
6
11
laravel new datatables
7
-
cd datatables
8
12
```
9
13
10
-
## Setup Laravel UI
14
+
After the project has been created, we will then install [Laravel UI](https://github.com/laravel/ui) and [Yajra DataTables](https://github.com/yajra/laravel-datatables)
11
15
12
16
```shell
17
+
cd datatables
18
+
13
19
composer require laravel/ui --dev
14
20
php artisan ui bootstrap --auth
15
-
```
16
-
17
-
## Install Laravel DataTables
18
21
19
-
```shell
20
22
composer require yajra/laravel-datatables:^9.0
21
23
```
22
24
23
-
## Setup database and ENV configuration
24
-
25
-
Create a new database and update `.env` file and set the database credentials.
25
+
For simplicity, you may use SQLite to store your application's data. To instruct Laravel to use SQLite instead of MySQL, update your new application's `.env` file and remove all of the `DB_*` environment variables except for the `DB_CONNECTION` variable, which should be set to `sqlite`:
We just need to start the Vite development server to automatically recompile our JS, CSS and refresh the browser when we make changes to our Blade templates:
81
77
82
-
```
78
+
```shell
83
79
npm run dev
84
80
```
85
81
86
-
## Create and update UsersDataTable
82
+
<aname="setup-users-datatable"></a>
83
+
## <b>03.</b> Setup a Users DataTable
87
84
88
-
Create a new DataTable class:
85
+
Open a new terminal in your `datatables` project directory and run the following command:
89
86
90
87
```shell
91
88
php artisan datatables:make Users
92
89
```
93
90
94
-
Then, update the `getColumns()` with the users fields:
91
+
Next, we will configure our `UsersDataTable` and add the columns that we want to display.
95
92
96
-
```php
93
+
```php filename=app/DataTables/UsersDataTable.php
97
94
namespace App\DataTables;
98
95
99
96
use App\Models\User;
@@ -135,7 +132,7 @@ class UsersDataTable extends DataTable
135
132
]);
136
133
}
137
134
138
-
protected function getColumns(): array
135
+
public function getColumns(): array
139
136
{
140
137
return [
141
138
Column::make('id'),
@@ -153,15 +150,14 @@ class UsersDataTable extends DataTable
153
150
}
154
151
```
155
152
156
-
## Create and update the users controller
157
-
158
-
Create a new controller and add the following:
153
+
<aname="setup-users-controller"></a>
154
+
## <b>04.</b> Setup a Users Controller, View & Route
Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman
232
225
>>> User::factory(100)->create()
233
226
```
234
227
235
-
## Access Users DataTables
228
+
Our application should now be ready to run.
229
+
230
+
```shell
231
+
php artisan serve
232
+
```
233
+
234
+
Once you have started the Artisan development server, your application will be accessible in your web browser at [http://localhost:8000]([http://localhost:8000).
236
235
237
-
http://datatables.test/users
236
+
We can now visit our [`/users`](http://localhost:8000/users) via route and see our users table.
0 commit comments