laraveldaily/apigenerator

API Generator for Laravel 5
1,203 86
Install
composer require laraveldaily/apigenerator
Latest Version:0.1.9
License:MIT
Last Updated:Oct 10, 2019
Links: GitHub  ·  Packagist
Maintainer: Laraveldaily

API Generator for Laravel 5.4 and above

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

  1. Install the package via composer require laraveldaily/apigenerator

  2. Add Laraveldaily\Apigenerator\ApiGeneratorProvider::class to your config\app.php providers.

  3. 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

Related Packages

erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

614,907,009 9,702
laravel/framework

The Laravel Framework.

554,918,666 34,821
laravel/tinker

Powerful REPL for the Laravel framework.

468,807,761 7,441