A lightway implementation of Laravel's belongs To many

Overview

LazyBelongsToMany

A lightweigth implementation of Laravel's belongs To many relationship in cases you don't need pivot table.

Installation

First, install the package through Composer.

composer require inani/lazy-belongs-to-many

Usage

Suppose we have the following database structure. A User can be linked to one or many Tag. instead of creating the pivot table we can save tags id list in a column on the user table.

| id | name              | tags_id       |
|----|-------------------|---------------|
| 1  | El Houssain inani | [1, 10, 4, 33]|


namespace Models;

use Illuminate\Database\Eloquent\Model;
use Inani\LazyBelongsToMany\Relations\BelongsToManyCreator;

class User extends Model
{
    use BelongsToManyCreator;
    
    protected $casts = [
      'tags_id' => 'array' // <=== IMPORTANT
    ];
    
    
    /**
    * Tags
     * @return mixed
    */
    public function tags()
    {
        return $this->belongsToManyInArray(Tag::class);
    }
}

For the time being there is no implementation for the inverse. I'll be happy to see your contribution at any way.

Happy Coding.

You might also like...
Easy Laravel Server-Side implementation of PrimeVue Datatables

Laravel + PrimeVue Datatables This is a simple, clean and fluent serve-side implementation of PrimeVue Datatables in Laravel. Features Global Search i

This is a solution implementation for the coderbyte question, CLEAN GET REQUEST RESULT.

This is a solution implementation for the coderbyte question, CLEAN GET REQUEST RESULT. Two solutions are proposed, the first is a brute force approach while the other is an improved time complexity solution.

Fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent Resources, Translatability, and Swagger.

Laravel Headless What about? This allows a fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent R

Composer repository implementation for ZIPs.

Release Belt — Composer repo for ZIPs Release Belt is a Composer repository, which serves to quickly integrate third–party non–Composer releases into

A lightweight domain event pattern implementation for Doctrine2.
A lightweight domain event pattern implementation for Doctrine2.

Knp Rad Domain Event A lightweight domain event pattern implementation for Doctrine2. Official maintainers: @Einenlum Installation With composer : $ c

PHP implementation of Nanoid, secure URL-friendly unique ID generator

Nanoid-php A tiny (179 bytes), secure URL-friendly unique string ID generator for JavaScript Safe. It uses cryptographically strong random APIs and gu

🍩 SweetAlert 2 Implementation for Laravel
🍩 SweetAlert 2 Implementation for Laravel

🟣 SweetAlert2 Support for Laravel Add beautiful alerts by SweetAlert directly into your Laravel application, with a simple setup, and handly helpers.

An easy-to-use virtual wallet implementation for Laravel.

Laravel Wallet Some apps require a prepayment system like a virtual wallet where customers can recharge credits which they can then use to pay in app

A straightforward implementation of the Circuit Breaker pattern for Laravel 9

Laravel Circuit Breaker A straightforward implementation of the Circuit Breaker pattern for Laravel Framework 9 (using Memcached). Installation You ca

Owner
Inani El Houssain
PHP Shinobi
Inani El Houssain
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
A package to flash multiple messages using Laravels default session message flashing system

Flash multiple advanced messages with both text, messages and links An opinionated solution for flashing multiple advanced messages from the backend a

Bilfeldt 6 Jan 18, 2022
Adds a way to write php and run it directly in Laravels' Artisan Tinker.

Adds a way to write php in PhpStorm/IDEA and run it directly as if through laravel artisan tinker - allowing you to quickly run a piece of code with a

Robbin 120 Jan 2, 2023
Laravel Belongs To User Package

If you are creating your own trait to have "belongsTo" User relationship in every model needed, you can also use this package not to define the trait on your own.

Umut Işık 5 Jul 7, 2022
Packagit is amazing laravel modules management, you could manage huge project with many separate laravel modules.

Packagit is amazing laravel modules management, you could manage huge project with many separate laravel modules.

null 364 Dec 12, 2022
Implementation Package Spatie/Laravel-Permission

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

M Rizal 3 Sep 12, 2021
A simple Socialite implementation for Laravel Jetstream.

Introduction Socialstream is a third-party package for Laravel Jetstream. It replaces the published authentication and profile scaffolding provided by

Joel Butcher 334 Jan 2, 2023
An easy-to-use virtual wallet implementation for Laravel

Laravel Wallet Some apps require a prepayment system like a virtual wallet where customers can recharge credits which they can then use to pay in app

Muath Assawadi 6 Sep 28, 2022
Repository Pattern implementation for Laravel

This is a Simple Repository Pattern implementation for Laravel Projects and an easily way to build Eloquent queries from API requests.

Ephraïm SEDDOR 1 Nov 22, 2021
A Gutenberg implementation for Laravel

Laraberg aims to provide an easy way to integrate the Gutenberg editor with your Laravel projects. It takes the Gutenberg editor and adds all the comm

Van Ons Internet Agency 1.2k Dec 22, 2022