Skip to content

Commit a560821

Browse files
authored
docs: bootcamp style quick starter
1 parent 98c518e commit a560821

File tree

1 file changed

+68
-68
lines changed

1 file changed

+68
-68
lines changed

quick-starter.md

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,62 @@
1-
# DataTables Quick Starter
1+
# Quick Starter
22

3-
## Create a new Laravel project
3+
<a name="installation"></a>
4+
## <b>01.</b> Installing Laravel & DataTables
45

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
611
laravel new datatables
7-
cd datatables
812
```
913

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)
1115

1216
```shell
17+
cd datatables
18+
1319
composer require laravel/ui --dev
1420
php artisan ui bootstrap --auth
15-
```
16-
17-
## Install Laravel DataTables
1821

19-
```shell
2022
composer require yajra/laravel-datatables:^9.0
2123
```
2224

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`:
2626

2727
```shell
2828
touch database/database.sqlite
2929
```
3030

31-
```dotenv
31+
```dotenv filename=.env
3232
DB_CONNECTION=sqlite
33-
DB_DATABASE=/absolute/path/to/database/database.sqlite
3433
```
3534

36-
```shell
37-
php artisan migrate
38-
```
35+
<a name="datatables-with-vite"></a>
36+
## <b>02.</b> Install Laravel DataTables Vite
3937

40-
## Install Laravel DataTables Vite Assets
38+
Next, we will install [Laravel DataTables Vite](https://github.com/yajra/laravel-datatables-vite) to simplify our frontend setup.
4139

4240
```shell
4341
npm i laravel-datatables-vite --save-dev
4442
```
4543

4644
This will install the following packages:
4745

48-
1. Bootstrap Icons
49-
2. DataTables with Buttons and Select plugins for Bootstrap 5
50-
3. Laravel DataTables custom scripts
51-
52-
## Register the package js and css
46+
```
47+
- Bootstrap Icons
48+
- DataTables with Buttons and Select plugins for Bootstrap 5
49+
- Laravel DataTables custom scripts
50+
```
5351

54-
Edit `resources/js/app.js` and add the following:
52+
Once installed, we can now configure our scripts and css needed for our application.
5553

56-
```js
54+
```js filename=resources/js/app.js
5755
import './bootstrap';
5856
import 'laravel-datatables-vite';
5957
```
6058

61-
Edit `resources/sass/app.scss` and add the following:
62-
63-
```postcss
59+
```postcss filename=resources/sass/app.scss
6460
// Fonts
6561
@import url('https://fonts.bunny.net/css?family=Nunito');
6662

@@ -77,23 +73,24 @@ Edit `resources/sass/app.scss` and add the following:
7773
@import 'datatables.net-select-bs5/css/select.bootstrap5.css';
7874
```
7975

80-
## Compile the assets
76+
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:
8177

82-
```
78+
```shell
8379
npm run dev
8480
```
8581

86-
## Create and update UsersDataTable
82+
<a name="setup-users-datatable"></a>
83+
## <b>03.</b> Setup a Users DataTable
8784

88-
Create a new DataTable class:
85+
Open a new terminal in your `datatables` project directory and run the following command:
8986

9087
```shell
9188
php artisan datatables:make Users
9289
```
9390

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.
9592

96-
```php
93+
```php filename=app/DataTables/UsersDataTable.php
9794
namespace App\DataTables;
9895

9996
use App\Models\User;
@@ -135,7 +132,7 @@ class UsersDataTable extends DataTable
135132
]);
136133
}
137134

138-
protected function getColumns(): array
135+
public function getColumns(): array
139136
{
140137
return [
141138
Column::make('id'),
@@ -153,15 +150,14 @@ class UsersDataTable extends DataTable
153150
}
154151
```
155152

156-
## Create and update the users controller
157-
158-
Create a new controller and add the following:
153+
<a name="setup-users-controller"></a>
154+
## <b>04.</b> Setup a Users Controller, View & Route
159155

160156
```shell
161157
php artisan make:controller UsersController
162158
```
163159

164-
```php
160+
```php filename=app/Http/Controllers/UsersController.php
165161
namespace App\Http\Controllers;
166162

167163
use App\DataTables\UsersDataTable;
@@ -175,26 +171,7 @@ class UsersController extends Controller
175171
}
176172
```
177173

178-
## Update the default app layout
179-
180-
Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app.blade.php`
181-
182-
```
183-
....
184-
<main class="py-4">
185-
@yield('content')
186-
</main>
187-
</div>
188-
@stack('scripts')
189-
</body>
190-
</html>
191-
```
192-
193-
## Create users index file
194-
195-
Create new file: `resources/views/users/index.blade.php`.
196-
197-
```php
174+
```blade filename=resources/views/users/index.blade.php
198175
@extends('layouts.app')
199176
200177
@section('content')
@@ -213,26 +190,49 @@ Create new file: `resources/views/users/index.blade.php`.
213190
@endpush
214191
```
215192

216-
## Register users route
217-
218-
Update `routes/web.php`.
219-
220-
```php
193+
```php filename=routes/web.php
221194
use App\Http\Controllers\UsersController;
222195

223196
Route::get('/users', [UsersController::class, 'index'])->name('users.index');
224197
```
225198

226-
## Create dummy data using tinker
199+
<a name="update-default-layout"></a>
200+
## <b>05.</b> Update the default app layout
227201

228-
```php
202+
To be able to load our custom scripts, we need to add `@stack('scripts')` before the end of `body` tag in our `app.blade.php` layout.
203+
204+
```blade filename=resources/views/layouts/app.blade.php
205+
....
206+
<main class="py-4">
207+
@yield('content')
208+
</main>
209+
</div>
210+
@stack('scripts')
211+
</body>
212+
</html>
213+
```
214+
215+
<a name="migrate-and-seed"></a>
216+
## <b>06.</b> Migrate and Seed Test Data
217+
218+
```shell
219+
php artisan migrate
229220
php artisan tinker
221+
```
230222

223+
```php
231224
Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman
232225
>>> User::factory(100)->create()
233226
```
234227

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).
236235

237-
http://datatables.test/users
236+
We can now visit our [`/users`](http://localhost:8000/users) via route and see our users table.
238237

238+
<img src="/img/screenshots/quick-starter.png" alt="Laravel DataTables Users" class="rounded-lg border dark:border-none shadow-lg" />

0 commit comments

Comments
 (0)