Laravel magical helpers such as Controllers / Requests / Models

Overview

Laravel Magic

GitHub last commit Latest Version on Packagist Packagist PHP Version Support GitHub top language Packagist License GitHub code size in bytes GitHub all releases Packagist Stars

Laravel Magic provides Abstract Controller, Model, generic Request, Traits, Exceptions and various middlewares in order to generate very easily and quickly API resources from scratch.

Support us

Laravel Magic is a free open source project. If you use the project, please star us on Github... it costs nothing but a click! 😉

Installation

You can install the package via composer:

composer require dominiquevienne/laravel-magic

This package does not provide

  • any migration
  • any configuration file
  • any view

Usage

Models

Extending your models from AbstractModel will give you the opportunity to get the autocompletion that comes with PHPDoc in your IDE and will make it possible to check if a relationship exist for the given model.

It will also make it possible for AbstractController to make the magic happen. (see Controllers).



namespace App\Models;

use Dominiquevienne\LaravelMagic\Models\AbstractModel;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * @property-read int $id
 * Your PHPDoc goes here 
 */
class YourModel extends AbstractModel
{
    use HasFactory;

    protected $fillable = [
    // ...
    ];
}

Controllers

Extending your controllers from AbstractController will give you the opportunity to get a fully automated way to generate index, show, destroy, update, store methods without writing a single controller line. This will fill 90% of the API Resource needs.

Since default methods are already available in AbstractController, you can directly configure your routes to target the usual methods and magic will happen.



namespace App\Http\Controllers;

use Dominiquevienne\LaravelMagic\Http\Controllers\AbstractController;

class YourController extends AbstractController
{
}

Relationships

When calling an index or show endpoint, you can add the with GET parameter in order to retrieve direct relationships of a given model. The API will not throw an error / warning if relationship is not available.

If the property is not provided or if value is empty after sanitization, the query will result in a normal query without any relationship retrieval.

Fields

When calling an index or show endpoint, you can add the fields GET parameter in order to only retrieve the listed fields. The API will not throw an error / warning if field is not available.

If the property is not provided or if value is empty after sanitization, the query will throw every available fields.

Filtering

When calling an index endpoint, you can add the filter GET parameter in order to filter the list so you only retrieve the row you targeted. The API will not throw an error / warning if the fields you use for filtering are not available.

If the property is not provided or if value is empty after sanitization, the query will result in a normal query retrieving all the rows.

Ordering

When calling an index endpoint, you can add the filter GET parameter in order to order the provided result is ordered the way you need.

The API will throw an error if you provide a non compliant string.

If the property is not provided, the query will result in a normal query retrieving all the rows without any specific sorting.

Pagination

The standard Laravel pagination is integrated. Please refer to the official paginate documentation.

Requests

Laravel Magic provides a BootstrapRequest file which will be call on any AbstractConctroller.create and AbstractConctroller.update methods. If a request which name is ModelnameRequest is available in your Requests folder, it will be used to generate the validation rules.

Middlewares

Laravel Magic provides ForceJson and VerifyJwtToken middlewares. Those can be set up in Laravel Kernel.

Traits

We also provide a HasPublicationStatus trait. To use the trait, add it to your models and migrate your schema so it has the publication_status_id field. Value of this field is handled by $publicationStatusAvailable property.

Exceptions

Laravel Magic provides those Exceptions:

  • ControllerAutomationException
  • EnvException
  • PublicationStatusException
  • StatusUnknownException

These are used internally but you can of course use them as you want.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Scripts, helpers and configs to make hacking on Synack less painful

SynackMoPleasure Scripts, helpers and configs to make hacking on Synack less painful TuPOC HTTP OOB PHP Logger This PHP script was created to test/exp

Laravel SEO - This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

A simple Laravel package for generating download links with options such as expire time, IP restrictions, etc.

Generate download links in your Laravel applications This package allows you to generate download links for files. Once installed you can do stuff lik

This is a courier api endpoints library for interacting such as e-courier, dhl, pathao etc

This is a courier api endpoints library for interacting such as e-courier, dhl, pathao etc Installation Step 1: composer require xenon/multicourier S

Dashboard to view your http client requests in laravel application
Dashboard to view your http client requests in laravel application

Laravel Blanket is a package with wraps laravel http client requests and provide logs for request and response, also give option to retry any request from dashboard and more...

Make requests to the Shopify API from your Laravel app
Make requests to the Shopify API from your Laravel app

Make requests to the Shopify API from your Laravel app The signifly/laravel-shopify package allows you to easily make requests to the Shopify API. Ins

Execute Laravel Artisan commands via REST APIs and HTTP requests safely.

Artisan Api There might be some times you wanted to execute an Artisan command, but you did not have access to shell or SSH. Here we brought REST API

This package provides convenient methods for making token code, sending and verifying mobile phone verification requests.
This package provides convenient methods for making token code, sending and verifying mobile phone verification requests.

Laravel Mobile Verification Introduction Many web applications require users to verify their mobile phone numbers before using the application. Rather

Log requests and group together for aggregated statistics of route usage
Log requests and group together for aggregated statistics of route usage

Log Laravel route usage statistics Log Laravel requests and responses for statistical purposes and optionally aggregate by hours/days/months for minim

Comments
Releases(v1.7.0)
  • v1.7.0(May 30, 2022)

  • v1.5.0(May 19, 2022)

    This new public method gives the opportunity to create api routes which will return validation rules for the related model

    Full Changelog: https://github.com/dominiquevienne/laravel_magic/compare/v1.4.0...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(May 18, 2022)

  • v1.3.1(May 9, 2022)

  • v1.3(May 4, 2022)

    What's Changed

    • Documentation creation by @dominiquevienne in https://github.com/dominiquevienne/laravel_magic/pull/2
    • Using Session to store JWT by @dominiquevienne in https://github.com/dominiquevienne/laravel_magic/pull/3

    New Contributors

    • @dominiquevienne made their first contribution in https://github.com/dominiquevienne/laravel_magic/pull/2

    Full Changelog: https://github.com/dominiquevienne/laravel_magic/compare/v1.2...v1.3

    Source code(tar.gz)
    Source code(zip)
  • v1.2(May 3, 2022)

  • v1.1(May 3, 2022)

  • v1.0(May 3, 2022)

Owner
Dominique Vienne
Dominique Vienne
Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Laravel Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT cs

Tina Hammar 7 Nov 23, 2022
Automatically load your helpers in your laravel application.

Laravel AutoHelpers Automatically load your helpers in your laravel application. Installation You can install the package via composer: composer requi

Florian Wartner 6 Jul 26, 2021
Laravel translation helpers

Laravel Translator Installation and setup Installation You can install the package via composer: composer require isaeken/laravel-translator Setup You

Ä°sa Eken 5 Aug 12, 2022
Laravel Helpers Automatic Loading System

About Laravel Helpers Automatic Load Laravel Helpers Automatic Loading System Doc: Copy the Helpers folder and paste it on app folder Then Go To app/P

IQBAL HASAN 2 Nov 9, 2021
Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css. Requires Livewire and AlpineJS.

Laravel Livewire Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size W

Tina Hammar 15 Oct 6, 2022
Laravel breeze is a PHP Laravel library that provides Authentication features such as Login page , Register, Reset Password and creating all Sessions Required.

About Laravel breeze To give you a head start building your new Laravel application, we are happy to offer authentication and application starter kits

null 3 Jul 30, 2022
Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Limewell 30 Dec 24, 2022
SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).

SEO Helper By ARCANEDEV© SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization). Feel free to check out the rele

ARCANEDEV 301 Nov 25, 2022
Collection of agnostic PHP Functions and helpers with zero dependencies to use as foundation in packages and other project

Collection of agnostic PHP Functions and helpers This package provides a lot of very usefull agnostic helpers to use as foundation in packages and oth

padosoft 54 Sep 21, 2022
Because I can never remember exactly how to autoload my helpers.php file.

Laravel Helpers File (helpers.php) I add a app/helpers.php file to every project for any custom helpers I might want to create. Everytime I go to add

Caleb Porzio 59 Mar 31, 2022