Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwadhams committed Jul 2, 2024
1 parent b9e5f9b commit 0b06ff8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Single Table Inheritance
[![Latest Unstable Version](https://poser.pugx.org/nanigans/single-table-inheritance/v/unstable.svg)](https://packagist.org/packages/nanigans/single-table-inheritance)
[![License](https://poser.pugx.org/nanigans/single-table-inheritance/license.svg)](https://packagist.org/packages/nanigans/single-table-inheritance)

Single Table Inheritance is a trait for Laravel 5.8+ Eloquent models that allows multiple models to be stored in the same database table. We support a few key features
Single Table Inheritance is a trait for Laravel 9+ Eloquent models that allows multiple models to be stored in the same database table. We support a few key features

* Implemented as a Trait so that it plays nice with others, such as Laravel's `SoftDeletingTrait` or the excellent [Validating](https://github.com/dwightwatson/validating), without requiring a complicated mess of Eloquent Model subclasses.
* Allow arbitrary class hierarchies not just two-level parent-child relationships.
Expand All @@ -22,15 +22,17 @@ Single Table Inheritance is a trait for Laravel 5.8+ Eloquent models that allows
Simply add the package to your `composer.json` file and run `composer update`.

```
"nanigans/single-table-inheritance": "~1.0"
"carsdotcom/single-table-inheritance": "^1.0.1"
```

Or go to your project directory where the `composer.json` file is located and type:

```sh
composer require "nanigans/single-table-inheritance:~1.0"
composer require "carsdotcom/single-table-inheritance:^1.0.1"
```

For Laravel before 9.x you can still use [jonspalmer/single-table-inheritance:1.0.0](https://github.com/jonspalmer/single-table-inheritance)

# Overview

Getting started with the Single Table Inheritance Trait is simple. Add the constraint and add a few properties to your models. A complete example of a `Vehicle` super class with two subclasses `Truck` and `Car` is given by
Expand Down Expand Up @@ -158,7 +160,7 @@ Unfortunately there is no efficient way to automatically detect BelongsTo foreig

### Throwing Exceptions for Invalid Attributes

BY default the SingleTableInheritanceTrait will handle invalid attributes silently It ignores non-persisted attributes when a model is saved and ignores non-persisted columns when hydrating a model from a builder query. However, you can force exceptions to be thrown when invalid attributes are encountered in either situation by setting the `$throwInvalidAttributeExceptions` property to true.
By default, the SingleTableInheritanceTrait will handle invalid attributes silently It ignores non-persisted attributes when a model is saved and ignores non-persisted columns when hydrating a model from a builder query. However, you can force exceptions to be thrown when invalid attributes are encountered in either situation by setting the `$throwInvalidAttributeExceptions` property to true.

```php
/**
Expand All @@ -175,7 +177,7 @@ protected static $throwInvalidAttributeExceptions = true;

We've chosen a very particular implementation to support single table inheritance. However, others have written code and articles around a general approach that proved influential.

First, Mark Smith has an excellent article (no long live but available in web archive) [Single Table Inheritance in Laravel 4](https://web.archive.org/web/20171224233536/http://www.colorfultyping.com/single-table-inheritance-in-laravel-4/) amongst other things is introduces the importance of queries returning objects of the correct type. Second, Jacopo Beschi wrote and extension of Eloquent's `Model`, [Laravel-Single-Table-Inheritance](https://github.com/intrip/laravel-single-table-inheritance)`, that introduces the importance of being able to define which attributes each model persists.
First, Mark Smith has an excellent article (no long live but available in web archive) [Single Table Inheritance in Laravel 4](https://web.archive.org/web/20171224233536/http://www.colorfultyping.com/single-table-inheritance-in-laravel-4/) amongst other things it introduces the importance of queries returning objects of the correct type. Second, Jacopo Beschi wrote and extension of Eloquent's `Model`, [Laravel-Single-Table-Inheritance](https://github.com/intrip/laravel-single-table-inheritance)`, that introduces the importance of being able to define which attributes each model persists.

The use of Traits was heavy influence by the Eloquent's `SoftDeletingTrait` and the excellent [Validating Trait](https://github.com/dwightwatson/validating).

Expand Down
17 changes: 0 additions & 17 deletions phpunit.xml.bak

This file was deleted.

0 comments on commit 0b06ff8

Please sign in to comment.