All Projects → ponich → eloquent-traits

ponich / eloquent-traits

Licence: MIT License
Traits for laravel eloquent models

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to eloquent-traits

Pecee Pixie
Lightweight, easy-to-use querybuilder for PHP inspired by Laravel Eloquent - but with less overhead.
Stars: ✭ 19 (+5.56%)
Mutual labels:  eloquent, models
Laravel Model Cleanup
Clean up unneeded records
Stars: ✭ 388 (+2055.56%)
Mutual labels:  eloquent, models
laravel-parallel
Laravel parallel
Stars: ✭ 41 (+127.78%)
Mutual labels:  eloquent
reactools
Create React interfaces is easy.
Stars: ✭ 14 (-22.22%)
Mutual labels:  helpers
userstamps
A simple package to insert and load userstamps for a model automatically, it provides an eloquent trait to use in models..
Stars: ✭ 34 (+88.89%)
Mutual labels:  eloquent
laravel-eloquent-relationships-gravit-designer
Graphic showing Laravel Eloquent ORM Relationships
Stars: ✭ 19 (+5.56%)
Mutual labels:  eloquent
bigscience
Central place for the engineering/scaling WG: documentation, SLURM scripts and logs, compute environment and data.
Stars: ✭ 261 (+1350%)
Mutual labels:  models
laravel-local-class-scope
A tiny macro that reuse a global scope class as a local scope
Stars: ✭ 16 (-11.11%)
Mutual labels:  eloquent
model-observers
Make model observers easy
Stars: ✭ 17 (-5.56%)
Mutual labels:  eloquent
laravel-repository
Repository pattern implementation for Laravel
Stars: ✭ 49 (+172.22%)
Mutual labels:  eloquent
eloquent-has-by-non-dependent-subquery
Convert has() and whereHas() constraints to non-dependent subqueries.
Stars: ✭ 70 (+288.89%)
Mutual labels:  eloquent
model-zoo-old
The ONNX Model Zoo is a collection of pre-trained models for state of the art models in deep learning, available in the ONNX format
Stars: ✭ 38 (+111.11%)
Mutual labels:  models
MercadoLivreProductsCrawler
PHP Console Crawler to Download Products from a Store on MercadoLivre.com.br
Stars: ✭ 18 (+0%)
Mutual labels:  eloquent
eloquent-phpunit
Eloquent model and database schema PHPUnit test case
Stars: ✭ 20 (+11.11%)
Mutual labels:  eloquent
laravel-hashid
HashId Implementation on Laravel Eloquent ORM
Stars: ✭ 23 (+27.78%)
Mutual labels:  eloquent
laravel-loggable
🎥 📽 🎞 Log your model changes in multiple ways
Stars: ✭ 58 (+222.22%)
Mutual labels:  eloquent
laravel-eloquent-spatial
Laravel Eloquent spatial package.
Stars: ✭ 90 (+400%)
Mutual labels:  eloquent
spacy-universal-sentence-encoder
Google USE (Universal Sentence Encoder) for spaCy
Stars: ✭ 102 (+466.67%)
Mutual labels:  models
condvis
Visualisation for statistical models.
Stars: ✭ 20 (+11.11%)
Mutual labels:  models
laravel-geoly
Perform fast and efficient radius searches on your Laravel Eloquent models.
Stars: ✭ 25 (+38.89%)
Mutual labels:  eloquent

Traits for Eloquent Models

Build Status License Latest Stable Version Total Downloads

This package adds the ability to use traits in you Laravel Eloquent Models

Traits list

Installation

This package can be used in Laravel 5.5 or higher.

composer require ponich/eloquent-traits

You can publish the migration with:

php artisan vendor:publish --provider="Ponich\Eloquent\Traits\ServiceProvider" --tag="migrations"

After the migration has been published you can create tables by running the migrations:

php artisan migrate

Traits

Virtual Attributes

Adds the ability to create virtual attributes in your model.

Use trait: \Ponich\Eloquent\Traits\VirtualAttribute

Example:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use \Ponich\Eloquent\Traits\VirtualAttribute;

    protected $table = 'posts';

    protected $guarded = ['id'];

    public $virtalAttributes = ['tags', 'og_tags'];
}

In the property of the class $virtalAttributes list all valid virtual attributes.

$post = Post::firstOrFail(1);

$post->tags = ['tag1', 'tag2', 'tag3'];
$post->save();

$post->refresh();

var_dump($post->tags); 
/**
    array(3) {
      [0]=>
      string(4) "tag1"
      [1]=>
      string(4) "tag2"
      [2]=>
      string(4) "tag3"
    }
*/

Attachments

Allows links files to models

Use trait: \Ponich\Eloquent\Traits\HasAttachment

Example:

Model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use \Ponich\Eloquent\Traits\HasAttachment;

    protected $table = 'posts';

    protected $guarded = ['id'];
}

Add attachment :

$post = Post::findOrFail(1);

// by path
$post->attach('/path/to/file');

// by request
$post->attach(
    $request->file('photo')
);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].