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: README.md
+63-8Lines changed: 63 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,21 @@
14
14
15
15
Automatically Route Generator Package for Laravel.
16
16
17
+
## Features
18
+
- All HTTP Methods which supported by Laravel
19
+
- AJAX supported HTTP Methods (XMLHttpRequest)
20
+
- Custom patterns for parameters with Regex
21
+
- kebab-case and snake_case supported URLs
22
+
17
23
## Install
18
24
19
25
*Supported Laravel Versions:***>= 6.x**
20
26
21
-
composer.json file:
27
+
Run the following command directly in your Project path:
28
+
```
29
+
$ composer require izniburak/laravel-auto-routes
30
+
```
31
+
**OR** open your `composer.json` file and add the package like this:
22
32
```json
23
33
{
24
34
"require": {
@@ -31,12 +41,6 @@ after run the install command.
31
41
$ composer install
32
42
```
33
43
34
-
**OR** Run the following command directly in your Project path:
35
-
36
-
```
37
-
$ composer require izniburak/laravel-auto-routes
38
-
```
39
-
40
44
The service provider of the Package will be **automatically discovered** by Laravel.
41
45
42
46
After that, you should publish the config file via following command:
@@ -68,7 +72,7 @@ use Buki\AutoRoute\AutoRouteFacade as Route;
68
72
```
69
73
- All methods which will be auto generated must have `public` accessor to discovered by the **AutoRoute** Package.
70
74
71
-
75
+
### Methods
72
76
- If you use `camelCase` style for your method names in the Controllers, these methods endpoints will automatically convert to `kebab-case` to make pretty URLs. For example:
73
77
```php
74
78
Route::auto('/test', 'TestController');
@@ -149,6 +153,56 @@ class TestController extends Controller
149
153
}
150
154
```
151
155
156
+
### Ajax Supported Methods
157
+
158
+
Also, you can add **AJAX supported** routes. For example; If you want to have a route which only access with GET method and XMLHttpRequest, you can define it simply.
159
+
This package has some AJAX supported methods. These are;
* This method will only work with 'GET' method and XMLHttpRequest.
173
+
*/
174
+
public function xgetFoo(Request $request)
175
+
{
176
+
// your codes
177
+
}
178
+
179
+
/**
180
+
* URL: "/test/bar"
181
+
* This method will only work with 'POST' method and XMLHttpRequest.
182
+
*/
183
+
public function xpostBar(Request $request)
184
+
{
185
+
// your codes
186
+
}
187
+
188
+
/**
189
+
* URL: "/test/baz"
190
+
* This method will work with any method and XMLHttpRequest.
191
+
*/
192
+
public function xanyBaz(Request $request)
193
+
{
194
+
// your codes
195
+
}
196
+
}
197
+
```
198
+
As you see, you need to add only `x` char as prefix to define the AJAX supported routes.
199
+
If you want to support XMLHttpRequest and all HTTP methods which supported by Laravel, you can use `xany` prefix.
200
+
201
+
For AJAX supported methods, the package will automatically add a middleware in order to check XMLHttpRequest for the routes.
202
+
This middleware throws a `MethodNotAllowedException` exception. But, you can change this middleware from `auto-routes.php` file in `config` directory, if you want.
203
+
204
+
### Options
205
+
152
206
- You can add route options via third parameter of the `auto` method.
153
207
```php
154
208
Route::auto('/test', 'TestController', [
@@ -215,6 +269,7 @@ class TestController extends Controller
215
269
}
216
270
}
217
271
```
272
+
### Parameters
218
273
- You can use parameters as `required` and `optional` for the methods in your Controllers. For example;
0 commit comments