# Prepare Models
There are several options for working with Eloquent.
- With the
CastPricing
: cast a model attribute to a single Pricing instance. - With the
CastMultiPricing
: cast a model attribute to aCollection
of Pricing instances. Allows dynamic creation. - With the
HasPricing
trait: provides a utility methods for working with named pricing instances.
use Illuminate\Database\Eloquent\Model;
use MOIREI\Pricing\HasPricing;
use MOIREI\Pricing\CastPricing;
use MOIREI\Pricing\CastMultiPricing;
class Product extends Model
{
use HasPricing; // option 3
/**
* The attributes that should be casted to media types.
*
* @var array
*/
protected $casts = [
'pricing' => CastPricing::class, // option 1
'international_pricing' => CastMultiPricing::class, // option 2
];
...
}
In your database
...
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
...
$table->json('pricing');
// $table->json('international_pricing');
// or
$table->text('pricing');
});
...
}