Git Product home page Git Product logo

bless_model's Introduction

BlessModel

The purpose of this package is to save, update, delete, force delete, and restore data using a recursive array. It understands both an associative array for working with one record, and with a dataset for working with several records at once.

Installation

You can install the library using composer:

composer require bfg/bless_model

Beginning of work

First, you need to design your models and their relationships.

How to use

For convenience, the main method has been brought into the alias BlessModel. All you need to do is call the do method.

\BlessModel::do(\App\Models\User::class, []);

Let's imagine that our user model has the following relationships:

profile - hasOne

class Profile extends \Illuminate\Database\Eloquent\Model {
   
    protected $fillable = ["first_name","last_name","age","about"];
}

roles - belongsToMany

class Role extends \Illuminate\Database\Eloquent\Model {
   
    protected $fillable = ["slug","name"];
}

posts - hasMany

class Post extends \Illuminate\Database\Eloquent\Model {
   
    protected $fillable = ["subject","text"];
}

commentaries - morphMany

class Commentary extends \Illuminate\Database\Eloquent\Model {
   
    protected $fillable = ["text"];
}

And in order to fill in this data, you need to do the following:

\BlessModel::do(\App\Models\User::class, [
    "name" => "DoctorWho",
    "email" => "[email protected]",
    "profile" => [
        "first_name" => "Doctor",
        "last_name" => "Who",
        "age" => 2200,
        "about" => "An eccentric alien traveler of a great mind who fights injustice."
    ],
    "role" => [
        "slug" => "time_lord",
        "name" => "Time Lord",
    ],
    "posts" => [
        [
            "subject" => "About TARDIS",
            "text" => "The TARDIS (Time And Relative Dimension In Space) is a time machine and spacecraft that appears in the British science fiction television series Doctor Who and its various spin-offs."
        ]       
    ],
    "commentaries" => [
        [
            "text" => "Butterflies are cool!"
        ],
        [
            "text" => "Yowzah!"
        ],
        [
            "text" => "Geronimo!"
        ]
    ]
]);

bless_model's People

Contributors

xsaven avatar

Stargazers

 avatar

Watchers

 avatar BFG avatar

Forkers

woub-chat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.