Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

API Generator

Generate API with single command

Use

Suppose we created module using php artisan make:crud Faq.

Now we need to generate API for that module

Well it can be done by using following command :-

php artisan make:api Faq

What it does

  1. Creates client consummable API

  2. Creates Restful API

  3. Creates Resource(Resources/Faq/FaqResource) and CollectionResource(Resources/Faq/FaqCollection)

  4. Creates ClientAPIController(Controller/Admin/API/Client/FaqClientAPIController) and RestAPIController(Controller/Admin/API/Restful/FaqRestAPIController)

Client API

If you only want to generate client consummable API only

php artisan make:api Faq --client

ClientAPIController Example

//Controller/Admin/API/Client/FaqClientAPIController
<?php

namespace App\Http\Controllers\Admin\API\Client;

use App\Models\Admin\Faq;
use App\Http\Resources\Faq\FaqCollection;
use App\Http\Resources\Faq\FaqResource;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class FaqClientAPIController extends Controller
{
 
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return new FaqCollection(Faq::all());
    }

    /**
     * Display the specified resource.
     *
     * @param  App\Models\Admin\Faq  $faq
     * @return \Illuminate\Http\Response
     */
    public function show(Faq $faq)
    {
        return new FaqResource($faq);
    }
}

Generated API

In api.php

Restful API

If you want to generate restful API only

RestAPIController Example

Generated API

In api.php

Last updated