Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Custom Properties Laravel Package

latevaweb/laravel-custom-properties

View on GitHub
Deep Wiki
Context7

Laravel Custom Properties

Trait to add dynamic custom properties to Eloquent models

Scrutinizer Code Quality Code Coverage Build Status StyleCI License: MIT Laravel 6.x

Once the trait is installed on the model and migration field is added you can do these things:

$customer = new Customer; // An Eloquent model
$customer
   ->setCustomProperty('foo', 'bar')
   ->setCustomProperty('foo2', 'bar2')
   ->save();
   
$customer->hasCustomProperty('foo'); // Returns 'true'

$customer->getCustomProperty('foo'); // returns 'bar'

$customer->forgetCustomProperty('foo'); // removes field 'foo' from model array

// Don't forget to persist it!

$customer->save();

Installation

You can install the package via composer:

composer require latevaweb/laravel-custom-properties

Adding custom properties to a Model

The required steps to add custom properties to a model are:

  • First, you need to add the LaTevaWeb\CustomProperties\HasCustomProperties-trait.
  • It is required to add to your model table the field $table->json('custom_properties')->nullable();

Here's an example of a prepared model:

use Illuminate\Database\Eloquent\Model;
use LaTevaWeb\CustomProperties\HasCustomProperties;

class NewsItem extends Model
{
    use HasCustomProperties;
}

And the migration:

Schema::table('your_table', function (Blueprint $table) {
    $table->json('custom_properties')->nullable();
});
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor