Skip to content

Commit d703fc0

Browse files
committed
Changelog added.
2 parents e60d679 + 2c4d862 commit d703fc0

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ All notable changes to `laravel-spatial` will be documented in this file
55
## 1.2.0 - 2012-02-08
66
- Laravel 9 support added.
77

8-
## 1.1.1 - 2012-01-20
9-
- axis-order added to setter of LocationCast.
10-
- axis-order added to query in HasSpatial trait.
8+
# 1.1.2 - 2022-03-08
9+
- Bug fixed for casting location columns that is null.
1110

12-
## 1.1.0 - 2012-01-20
13-
- Point type added to Doctrine mapped types in the service provider.
14-
- SRID support added to setter of LocationCast.
11+
# 1.1.1 - 2022-01-20
12+
- `axis-order` added to setter of `LocationCast`.
13+
- `axis-order` added to query in `HasSpatial` trait.
1514

16-
## 1.0.0 - 2012-01-18
15+
# 1.1.0 - 2022-01-20
16+
- `Point` type added to Doctrine mapped types in the service provider.
17+
- SRID support added to setter of `LocationCast`.
18+
19+
## 1.0.0 - 2022-01-18
1720
- initial release

src/Casts/LocationCast.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313

1414
class LocationCast implements CastsAttributes, SerializesCastableAttributes
1515
{
16-
public function get($model, string $key, $value, array $attributes): Point
16+
public function get($model, string $key, $value, array $attributes): ?Point
1717
{
18+
if (is_null($value)) {
19+
return null;
20+
}
21+
1822
$coordinates = explode(',', $value);
1923

2024
if (count($coordinates) > 1) {

tests/LocationCastTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ public function it_can_get_a_casted_attribute(): void
7373
$this->assertEquals($point->getSrid(), $address->location->getSrid());
7474
}
7575

76+
/** @test */
77+
public function it_returns_null_if_the_value_of_the_casted_column_is_null(): void
78+
{
79+
// 1. Arrange
80+
$address = new Address();
81+
82+
// 2. Act
83+
$address->save();
84+
85+
// 3. Assert
86+
$this->assertNull($address->location);
87+
}
88+
7689
/** @test */
7790
public function it_can_serialize_a_casted_attribute(): void
7891
{

tests/database/migrations/0000_00_00_000000_create_addresses_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function up(): void
1010
{
1111
Schema::create('addresses', function (Blueprint $table) {
1212
$table->id();
13-
$table->point('location');
13+
$table->point('location')->nullable();
1414
$table->timestamps();
1515
});
1616
}

0 commit comments

Comments
 (0)