Laravel magical helpers such as Controllers / Requests / Models

Last update: Apr 24, 2022

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.

GitHub

https://github.com/dominiquevienne/laravel_magic
You might also like...

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.

May 21, 2022

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

Nov 25, 2021

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

Jan 20, 2022

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

May 10, 2022

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

May 13, 2022

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

May 23, 2022

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

Apr 14, 2022

Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis Features Work with geometry classes instead of arrays. $model-myPoint = new Point(1,2); //lat

Apr 30, 2022

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.

Laravel-Mediable Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel. Features Filesystem-driven appro

May 11, 2022
Comments
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

Feb 10, 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

Jul 26, 2021
Laravel translation helpers
Laravel translation helpers

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

Jan 21, 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

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

Apr 14, 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

Apr 6, 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

May 19, 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

Feb 12, 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

Mar 31, 2022
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

Jan 23, 2022