mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
Merge pull request #269 from php-flasher/dev
update inertiajs documentation page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"dist/main.css": "/dist/main.123ef729.css",
|
||||
"dist/main.css": "/dist/main.28df35f9.css",
|
||||
"dist/main.js": "/dist/main.3be5bc06.js",
|
||||
"dist/455.3a7b4474.css": "/dist/455.3a7b4474.css",
|
||||
"dist/455.095e6545.js": "/dist/455.095e6545.js",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
"entrypoints": {
|
||||
"main": {
|
||||
"css": [
|
||||
"/dist/main.123ef729.css"
|
||||
"/dist/main.28df35f9.css"
|
||||
],
|
||||
"js": [
|
||||
"/dist/main.3be5bc06.js"
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-79
@@ -2,83 +2,5 @@
|
||||
permalink: /inertia/
|
||||
title: Inertia
|
||||
description: Discover how to integrate flash notifications into your Inertia.js application with PHPFlasher. Follow this guide to set up the library and enhance your user interface with dynamic messages.
|
||||
layout: inertia
|
||||
---
|
||||
|
||||
<strong><span class="text-indigo-900">PHP<span class="text-indigo-500">Flasher</span></span></strong> works well with Inertia.js.
|
||||
|
||||
## <i class="fa-duotone fa-list-radio"></i> Installation
|
||||
|
||||
To use **<strong><span class="text-indigo-900">PHP<span class="text-indigo-500">Flasher</span></span></strong>** with Inertia.js, install it the same way as in the [Laravel Installation](/laravel) guide.
|
||||
|
||||
Also, add `@flasher/flasher` to your `package.json`:
|
||||
|
||||
```json
|
||||
"@flasher/flasher": "file:vendor/php-flasher/flasher/Resources"
|
||||
```
|
||||
|
||||
Then, run:
|
||||
|
||||
```shell
|
||||
npm install --force
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## <i class="fa-duotone fa-list-radio"></i> Usage
|
||||
|
||||
Send `notifications` from your `HandleInertiaRequests` middleware.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// app/Http/Middleware/HandleInertiaRequests.php
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
public function share(Request $request): array
|
||||
{
|
||||
return array_merge(parent::share($request), [
|
||||
'messages' => flash()->render('array'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Then, display your `notifications` in your `Layout.vue` file:
|
||||
|
||||
```html
|
||||
// resources/js/Shared/Layout.vue
|
||||
<script>
|
||||
import flasher from "@flasher/flasher";
|
||||
|
||||
export default {
|
||||
props: {
|
||||
messages: Object,
|
||||
},
|
||||
watch: {
|
||||
messages(value) {
|
||||
flasher.render(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
Now, you can trigger notifications from anywhere in your application.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// app/Http/Controllers/UsersController.php
|
||||
class UsersController
|
||||
{
|
||||
public function store()
|
||||
{
|
||||
// your saving logic
|
||||
|
||||
flash()->success('User created.');
|
||||
|
||||
return Redirect::route('users');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user