Skip to content

Commit 8226ff8

Browse files
committed
- change name to laravel inertia route
- update readme for a beter documentation
1 parent 845d3ee commit 8226ff8

File tree

3 files changed

+100
-103
lines changed

3 files changed

+100
-103
lines changed

README.md

Lines changed: 95 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,117 @@
11
# Laravel Inertia Routes
22

3-
Render any inertia file inside a folder as html page auotmatically.
3+
```php
4+
/**
5+
* /resources/js/Pages/folder/component.vue
6+
* http://your-domain.com/folder/component
7+
*/
8+
InertiaRoute::get('folder/component');
9+
10+
/**
11+
* Change route:
12+
* /resources/js/Pages/folder/component.vue
13+
* http://your-domain.com/about
14+
*/
15+
InertiaRoute::get('about', 'folder/component');
16+
17+
/**
18+
* Automatically:
19+
* /resources/js/Pages/folder/component.vue
20+
* http://your-domain.com/folder/component
21+
*/
22+
InertiaRoute::bind('folder');
23+
24+
// change framework
25+
InertiaRoute::vue();
26+
InertiaRoute::react();
27+
InertiaRoute::svelte();
28+
```
429

5-
Instead of doing this:
30+
## Installation
31+
32+
```
33+
composer require jecovier/laravel-inertia-route
34+
```
35+
36+
## Usage
37+
38+
## Single component
639

740
```php
8-
Route::get('your/custom/route/home', function(){
9-
Inertia::render('path/to/component/home');
10-
});
11-
Route::get('your/custom/route/about', function(){
12-
Inertia::render('path/to/component/about');
13-
});
14-
Route::get('your/custom/route/contact', function(){
15-
Inertia::render('path/to/component/contact');
16-
});
17-
Route::get('your/custom/route/landing', function(){
18-
Inertia::render('path/to/component/landing');
19-
});
20-
```
21-
22-
you can do this:
41+
/**
42+
* /resources/js/Pages/folder/component.vue
43+
* http://your-domain.com/folder/component
44+
*/
45+
InertiaRoute::get('folder/component');
46+
47+
/**
48+
* Change route:
49+
* /resources/js/Pages/folder/component.vue
50+
* http://your-domain.com/about
51+
*/
52+
InertiaRoute::get('about', 'folder/component');
53+
InertiaRoute::get('/', 'folder/component');
54+
```
55+
56+
Also you can use other verbs:
2357

2458
```php
25-
InertiaRoute::bind('your/custom/route/', 'components/folder/');
59+
InertiaRoute::get('folder/component');
60+
InertiaRoute::post('folder/component');
61+
InertiaRoute::put('folder/component');
62+
InertiaRoute::delete('folder/component');
63+
InertiaRoute::patch('folder/component');
2664
```
2765

28-
Now if you visit http://localhost:8000/your/custom/route/about it will render /resources/js/Pages/path/to/component/about.vue (or react or svelte). All components that you create inside /resources/js/Pages/path/to/component/ will be automatically bind to a route like http://localhost:8000/your/custom/route/{component_name} 🤯.
66+
## Bind folder
2967

30-
Want to serve components from your root domain?
68+
Bind all components inside a folder:
3169

3270
```php
33-
InertiaRoute::bind('/', 'components/folder/');
71+
InertiaRoute::bind('some/folder/');
3472
```
3573

36-
**IMPORTANT!** InertiaRoute::bind use a "catch all" strategy, so put this route at the end of your route file or group.
74+
If you have components like:
3775

38-
## Installation
76+
```
77+
resources/js/Pages/components/folder/index.vue
78+
resources/js/Pages/components/folder/about.vue
79+
resources/js/Pages/components/folder/anotherPage.vue
80+
```
81+
82+
Now you can access them using:
3983

4084
```
41-
composer require jecovier/inertia-route
85+
http://yourdomain.com/some/folder/
86+
http://yourdomain.com/some/folder/about
87+
http://yourdomain.com/some/folder/anotherPage
4288
```
4389

44-
Requirements:
90+
You can change routes for folders using:
4591

46-
- PHP 7.3 | 8
47-
- Laravel 8
48-
- Inertia-Laravel 0.3.3
92+
```php
93+
InertiaRoute::bind('you/route', 'some/folder/');
94+
```
4995

50-
It's posible that this package works with older versions of PHP, Laravel or Inertia, but I don't have time to test it. If you try, please let me know 🙌.
96+
**IMPORTANT!** InertiaRoute::bind use a "catch all" strategy, so put this route at the end of your route file or group.
5197

52-
## What about parameters
98+
### Parameters
5399

54100
If you want to use route paramaters(without any backend proccess) you could define a route like this:
55101

56102
```php
57-
InertiaRoute::get('/your/custom/route/{parameter}', 'path/to/your/component');
103+
InertiaRoute::get('/route/{name}', 'folder/component');
58104
```
59105

60-
And in your component you will receive that variable as a prop:
106+
And your component will receive parameters as props:
61107

62108
vue:
63109

64110
```js
65111
<script>
66112
export default{
67113
props: {
68-
parameter: { required:true }
114+
name: { required:true }
69115
}
70116
}
71117
</script>
@@ -74,65 +120,38 @@ export default{
74120
svelte:
75121

76122
```js
77-
<script>export let parameter</script>
123+
<script>export let name</script>
78124
```
79125

80126
Reat:
81127

82128
```
83-
Someone could help me with a react example? 🙊
129+
// I don't know react :(
84130
```
85131

86-
## Middlewares... Prefixes... Can
87-
88-
InertiaRoute returns a Route object instance, so you can chained other methods:
132+
Also you can use:
89133

90134
```php
91-
InertiaRoute::get('/your/custom/route/{parameter}', 'path/to/your/component')
92-
->middleware('validateParameter')
93-
->can('viewThis');
94-
```
95-
96-
## I'm really lazy
97-
98-
```php
99-
InertiaRoute::get('path/to/component/{parameter}');
100-
InertiaRoute::bind('components/folder/');
135+
InertiaRoute::get('folder/component/{name}');
101136
```
102137

103-
This automatically bind the route your provide with the folder or component name. In this case:
138+
## Middlewares... Prefixes... Can...
104139

105-
```
106-
http://localhost:8000/path/to/component/{parameter}
107-
```
108-
109-
will be load:
110-
111-
```
112-
/resources/js/Pages/path/to/component/{parameter}.vue (react or svelte)
113-
```
114-
115-
... And for InertiaRoute::bind:
116-
117-
```
118-
http://localhost:8000/components/folder/hola
119-
```
120-
121-
will be load:
140+
InertiaRoute returns a Route object instance, so you can chained other methods:
122141

142+
```php
143+
InertiaRoute::get('/route/{parameter}', 'folder/component')
144+
->middleware('validateParameter')
145+
->can('viewThis');
123146
```
124-
/resources/js/Pages/components/folder/hola.vue (react or svelte)
125-
```
126-
127-
nice, right? 😎
128147

129-
## what if there is no component?
148+
## 404
130149

131150
InertiaRoute verifies if the file exist before try to render it. In case you want to access a non existing component, it will display a 404 page.
132151

133-
## I prefer Svelte or React
152+
## Svelte or React
134153

135-
Yeah, me too (svelte simp here 🙊). By default InertiaRoute will render Vue files, so in most cases you don't need to do anything. But, if you are working with React or Svelte, you could easily switch to those frameworks.
154+
By default InertiaRoute will render Vue files. But, if you are working with React or Svelte, you could easily switch to those frameworks.
136155

137156
In case of **React**:
138157

@@ -141,40 +160,18 @@ InertiaRoute::react();
141160
InertiaRoute::get('path/to/component/{parameter}');
142161
```
143162

144-
will be load:
145-
146-
```
147-
/resources/js/Pages/path/to/component/{parameter}.js
148-
```
149-
150163
And for **Svelte**:
151164

152165
```php
153166
InertiaRoute::svelte();
154167
InertiaRoute::get('path/to/component/{parameter}');
155168
```
156169

157-
will be load:
158-
159-
```
160-
/resources/js/Pages/path/to/component/{parameter}.svelte
161-
```
162-
163-
## Other Verbs?
164-
165-
I don't know why you want to do that 🤷... but you can!... just define your routes like:
166-
167-
```php
168-
InertiaRoute::get('/your/custom/route/{parameter}');
169-
InertiaRoute::post('/your/custom/route/{parameter}');
170-
InertiaRoute::put('/your/custom/route/{parameter}');
171-
InertiaRoute::patch('/your/custom/route/{parameter}');
172-
InertiaRoute::delete('/your/custom/route/{parameter}');
173-
```
170+
Remember to change framework before declare routes.
174171

175-
## I don't use /resources/js/Pages
172+
## Change root path
176173

177-
Inertiajs suggests this folder in its installation guide, however, you may be use another folder. If that is the case, you can change your root folder with:
174+
Inertiajs suggests resources/js/Pages as default folder, however, you may be use another path. If that is the case, you can change your root folder with:
178175

179176
```php
180177
InertiaRoute::root('your/new/path');

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "jecovier/inertia-route",
3-
"description": "use inertia components as pages",
2+
"name": "jecovier/laravel-inertia-route",
3+
"description": "Automatically create routes for any inertia component.",
44
"type": "library",
55
"require": {
66
"php": "^7.3|^8.0",
@@ -29,13 +29,13 @@
2929
"autoload": {
3030
"psr-4": {
3131
"App\\": "app/",
32-
"Jecovier\\InertiaRoute\\": "src"
32+
"Jecovier\\LaravelInertiaRoute\\": "src"
3333
}
3434
},
3535
"extra": {
3636
"laravel": {
3737
"aliases": {
38-
"InertiaRoute": "Jecovier\\InertiaRoute\\InertiaRoute"
38+
"InertiaRoute": "Jecovier\\LaravelInertiaRoute\\InertiaRoute"
3939
}
4040
}
4141
}

src/InertiaRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Jecovier\InertiaRoute;
3+
namespace Jecovier\LaravelInertiaRoute;
44

55
use Illuminate\Http\Request;
66
use Illuminate\Support\Facades\Route;

0 commit comments

Comments
 (0)