2017 © Pedro Peláez
 

library eloquent-traits

Traits for laravel eloquent models

image

ponich/eloquent-traits

Traits for laravel eloquent models

  • Thursday, July 12, 2018
  • by Ponich
  • Repository
  • 2 Watchers
  • 16 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 5 Versions
  • 200 % Grown

The README.md

Traits for Eloquent Models

Build Status License Latest Stable Version Total Downloads, (*1)

This package adds the ability to use traits in you Laravel Eloquent Models, (*2)

Traits list, (*3)

Installation

This package can be used in Laravel 5.5 or higher., (*4)

composer require ponich/eloquent-traits, (*5)

You can publish the migration with:, (*6)

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:, (*7)

php artisan migrate, (*8)

Traits

Virtual Attributes

Adds the ability to create virtual attributes in your model., (*9)

Use trait: \Ponich\Eloquent\Traits\VirtualAttribute, (*10)

Example:, (*11)

<?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., (*12)

$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, (*13)

Use trait: \Ponich\Eloquent\Traits\HasAttachment, (*14)

Example:, (*15)

Model:, (*16)

<?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 :, (*17)

$post = Post::findOrFail(1);

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

// by request
$post->attach(
    $request->file('photo')
);

The Versions

12/07 2018

dev-master

9999999-dev https://github.com/ponich/eloquent-traits

Traits for laravel eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nikolay Ponich

laravel eloquent attributes attachments activities

12/07 2018

1.0.3

1.0.3.0 https://github.com/ponich/eloquent-traits

Traits for laravel eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nikolay Ponich

laravel eloquent attributes attachments activities

12/07 2018

1.0.2

1.0.2.0 https://github.com/ponich/eloquent-traits

Traits for laravel eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nikolay Ponich

laravel eloquent attributes attachments activities

11/06 2018

1.0.1

1.0.1.0 https://github.com/ponich/eloquent-traits

Traits for laravel eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nikolay Ponich

laravel eloquent attributes attachments activities

24/05 2018

1.0.0

1.0.0.0 https://github.com/ponich/eloquent-traits

Traits for laravel eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nikolay Ponich

laravel eloquent attributes attachments activities