Skip to content

Commit 38455b7

Browse files
committed
test inertia
1 parent 7224043 commit 38455b7

File tree

13 files changed

+905
-13
lines changed

13 files changed

+905
-13
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Todo;
6+
use Illuminate\Http\Request;
7+
use Inertia\Inertia;
8+
9+
class DashboardController extends Controller
10+
{
11+
public function index()
12+
{
13+
return Inertia::render('Dashboard', [
14+
'user' => auth()->user(),
15+
'todos' => Inertia::defer(fn () => Todo::getTodayTodos()),
16+
]);
17+
18+
}
19+
20+
public function store(Request $request)
21+
{
22+
$validated = $request->validate([
23+
'title' => ['required', 'max:50'],
24+
]);
25+
$validated['user_id'] = auth()->user()->id;
26+
$validated['worked_at'] = now();
27+
Todo::create($validated);
28+
29+
return to_route('dashboard.index');
30+
}
31+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Http\Request;
6+
use Inertia\Middleware;
7+
8+
class HandleInertiaRequests extends Middleware
9+
{
10+
/**
11+
* The root template that's loaded on the first page visit.
12+
*
13+
* @see https://inertiajs.com/server-side-setup#root-template
14+
*
15+
* @var string
16+
*/
17+
protected $rootView = 'components.layouts.inertia';
18+
19+
/**
20+
* Determines the current asset version.
21+
*
22+
* @see https://inertiajs.com/asset-versioning
23+
*/
24+
public function version(Request $request): ?string
25+
{
26+
return parent::version($request);
27+
}
28+
29+
/**
30+
* Define the props that are shared by default.
31+
*
32+
* @see https://inertiajs.com/shared-data
33+
*
34+
* @return array<string, mixed>
35+
*/
36+
public function share(Request $request): array
37+
{
38+
return array_merge(parent::share($request), [
39+
//
40+
]);
41+
}
42+
}

bootstrap/app.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Middleware\HandleInertiaRequests;
34
use Illuminate\Console\Scheduling\Schedule;
45
use Illuminate\Foundation\Application;
56
use Illuminate\Foundation\Configuration\Exceptions;
@@ -23,6 +24,9 @@
2324
Request::HEADER_X_FORWARDED_PROTO |
2425
Request::HEADER_X_FORWARDED_AWS_ELB
2526
);
27+
$middleware->web(append: [
28+
HandleInertiaRequests::class,
29+
]);
2630
})
2731
->withExceptions(function (Exceptions $exceptions) {})
2832
->withSchedule(function (Schedule $schedule) {})

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"fakerphp/faker": "1.24.0",
1313
"feature-ninja/cva": "^0.3.0",
1414
"gehrisandro/tailwind-merge-laravel": "^1.2",
15+
"inertiajs/inertia-laravel": "^2.0",
1516
"laravel/cashier": "^15.6",
1617
"laravel/fortify": "1.24.5",
1718
"laravel/framework": "11.33.2",
@@ -25,6 +26,7 @@
2526
"silviolleite/laravelpwa": "^2.0",
2627
"spatie/laravel-settings": "^3.4",
2728
"stripe/stripe-php": "16.2.0",
29+
"tightenco/ziggy": "^2.5",
2830
"usernotnull/tall-toasts": "^2.1"
2931
},
3032
"require-dev": {

composer.lock

Lines changed: 145 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)