larafun/suite

A collection of classes and traits that will make you Laravel API workflow even more awesome!

v8.1.0 2021-07-26 09:07 UTC

This package is auto-updated.

Last update: 2024-10-26 21:24:47 UTC


README

Build Status Docs Status Latest Stable Version License Total Downloads

A small collection of classes and traits that will make your Laravel API development even more awesome!

Check out the full documentation in here larafun-suite.readthedocs.io

Installation

Requires PHP > 7.0, Laravel > 5.5

composer require larafun/suite

Basic Usage

Just make your Models extend Larafun\Suite\Model instead of use Illuminate\Database\Eloquent\Model

<?php

namespace App\Models;

use Larafun\Suite\Model;

class Book extends Model
{

}

Now you can use your models as you regularly would.

Why use this package?

Because you get enhanced Resources and Pagination out of the box!

class BookController extends Controller
{
    // ...

    public function index()
    {
        return Book::where('author', 'Isaac Asimov')->skip(2)->take(5)->get();
    }

Since the Book is an instance of Larafun\Suite\Model the results will be automatically presented inside a data property. Additionally, a meta field will be included and provide pagination information out of the box.

Switch back to the default behaviour?

The most easy way is to make your models extend Illuminate\Database\Eloquent\Model.

Otherwise you can fine tune your setup inside config/suite.php, after you publish it:

php artisan vendor:publish --provider=Larafun\\Suite\\ServiceProvider

TODO

These things should be added:

  • Add Validation to Filters
  • Add Formatters to Filters
  • Add Sanitizers to Filters
  • Change Filters behaviour to allow keys that do not have any defined defaults
  • Allow Filters to override values after instatiation
  • Split Filters into a separate package