Getting Started

Installation

Install Laravel Rest Api in a Laravel application, publish its configuration and add the optional packages.

Requirements

  • PHP 8.3 or higher
  • Laravel 13.30 or higher

Applications on Laravel 12 stay on version 2.x. An application on an earlier Laravel 13 release updates Laravel first:

composer update laravel/framework

Installing the package

Install the package with Composer:

composer require lomkit/laravel-rest-api

The service provider and the Rest facade register themselves through Laravel's package discovery.

Publish the configuration file when you want to change a default:

php artisan vendor:publish --tag=rest-config

This writes config/rest.php. Every key is described in Configuration. The package merges its defaults into your file at every level, so you can keep only the keys you change.

Optional packages

The package works without them. Install them for the features they bring:

PackageVersionBrings
laravel/sanctum or laravel/passportanyToken authentication for the routes that rest:quick-start adds
dedoc/scramble^0.13.48The OpenAPI document of every endpoint, see OpenAPI
laravel/scout^11.9Text search on a search engine, see Search engines
composer require dedoc/scramble:^0.13.48
Composer refuses a Scramble release outside 0.13.48 to 0.13.x, and a Scout release below 11.9, next to the package.

Setting up your first resources

The quickest way to get started is the rest:quick-start command. It asks which models to expose, then writes their resources, controllers, policies and routes, behind authentication:

php artisan rest:quick-start

Follow the Quick start to see what it writes and to send your first requests. To write a resource by hand, see Resources.

Upgrading from 2.x

Version 3.0 changes the declarations of resources, the payloads and the responses. Read the Upgrade guide before you update the package.