laraveldaily / apigenerator
API Generator for Laravel 5
Installs: 1 030
Dependents: 0
Suggesters: 0
Security: 0
Stars: 87
Watchers: 12
Forks: 21
Open Issues: 3
Requires
- laravel/framework: 5.4.*|5.5.*|5.6.*|5.7.*
README
Package to create API Controller and Route entry with one Artisan
command.
For now we're starting with only one simple command and will expand functionality as needed. Please submit your suggestions in Issues
section.
Notice: if you want to generate not only API, but full admin panel - check out our QuickAdminPanel.com
Installation and Usage
-
Install the package via
composer require laraveldaily/apigenerator
-
Add
Laraveldaily\Apigenerator\ApiGeneratorProvider::class
to yourconfig\app.php
providers. -
That's it: run
php artisan make:api --model=XXXXX
where XXXXX is your model name.
This command will generate API Controller and new entry in routes/api.php
file.
Notice: Model should exist already, our package won't create it.
Example
php artisan make:api --model=Project
Will generate the file app\Http\Controllers\Api\ProjectsController.php:
<?php
namespace App\Http\Controllers\Api;
use App\Project;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ProjectsController extends Controller
{
public function index()
{
return Project::all();
}
public function store(Request $request)
{
$project = Project::create($request->all());
return $project;
}
public function show($id)
{
return Project::findOrFail($id);
}
public function update(Request $request, $id)
{
$project = Project::findOrFail($id);
$project->update($request->all());
return $project;
}
public function destroy($id)
{
$project = Project::findOrFail($id);
$project->delete();
return '';
}
}
And this line will be added to routes/api.php
:
Route::resource('projects', 'Api/ProjectsController', ['except' => ['create', 'edit']]);
License
The MIT License (MIT). Please see License File for more information.
More from our LaravelDaily Team
- Check out our adminpanel generator QuickAdminPanel
- Read our Blog with Laravel Tutorials
- FREE E-book: 50 Laravel Quick Tips (and counting)
- Subscribe to our YouTube channel Laravel Business
- Enroll in our Laravel Online Courses