https://github.com/dlhck/lararest
The simplest way to generate CRUD API routes for Eloquent models in Laravel.
https://github.com/dlhck/lararest
eloquent laravel laravel-5-package rest-api
Last synced: about 2 months ago
JSON representation
The simplest way to generate CRUD API routes for Eloquent models in Laravel.
- Host: GitHub
- URL: https://github.com/dlhck/lararest
- Owner: dlhck
- Created: 2017-03-17T23:32:39.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T12:47:39.000Z (over 9 years ago)
- Last Synced: 2025-01-13T07:11:57.160Z (over 1 year ago)
- Topics: eloquent, laravel, laravel-5-package, rest-api
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LaraRest
[](https://packagist.org/packages/davidhoeck/lararest)
[](https://packagist.org/packages/davidhoeck/lararest)
[](https://packagist.org/packages/davidhoeck/lararest)
Keep your API routes file clean and generate your CRUD routes via LaraRest.
## STEP 1
Install LaraRest via Composer.
```
composer require davidhoeck/lararest
```
## STEP 2
Create your eloquent models.
## STEP 3
Go to your `api.php` in the `routes` folder.
## STEP 4
Initialize the `RestApiProvider`. Just paste the following lines of code,
at the top of your `api.php` file.
```
/** @var \DavidHoeck\LaraRest\RestApiProvider $apiProvider */
$apiProvider = new \DavidHoeck\LaraRest\RestApiProvider();
```
## STEP 5
Hook your models into the provider. Add every model your want your CRUD REST routes to be generate.
```
$apiProvider->addModel( new User() );
```
## EXAMPLE
The following line of code ...
```
$apiProvider->addModel( new User() );
```
... produces these routes.
| Method | URI | Name | Action | Middleware |
|---------|------------------------|-------------------|---------------------------------------------|------------|
|GET | api/users | api.users.index | App\Http\Controllers\UserController@index | api |
|DELETE | api/users | api.users.create | App\Http\Controllers\UserController@create | api |
|GET | api/users/paginate | api.users.paginate | App\Http\Controllers\UserController@paginate | api |
|GET | api/users/{id} | api.users.find | App\Http\Controllers\UserController@find | api |
|PUT | api/users/{id} | api.users.update | App\Http\Controllers\UserController@update | api |
|DELETE | api/users/{id} | api.users.delete | App\Http\Controllers\UserController@delete | api |