Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit b8aa6bb

Browse files
committed
Added stub searchable models to docker env.
1 parent d6545c5 commit b8aa6bb

15 files changed

+255
-182
lines changed

docker/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
*/data
2-
!*/data/.gitkeep

docker/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ services:
2323
dockerfile: Dockerfile
2424
volumes:
2525
- laravel:/app/laravel
26+
- ./laravel/app/Stubs:/app/laravel/app/Stubs
2627
networks:
2728
- default-net
2829
php:
@@ -38,6 +39,7 @@ services:
3839
volumes:
3940
- ./..:/app/driver
4041
- laravel:/app/laravel
42+
- ./laravel/app/Stubs:/app/laravel/app/Stubs
4143
networks:
4244
- default-net
4345
mysql:

docker/laravel/.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ BROADCAST_DRIVER=log
1616
CACHE_DRIVER=file
1717
SESSION_DRIVER=file
1818
SESSION_LIFETIME=120
19-
QUEUE_DRIVER=sync
19+
QUEUE_DRIVER=sync
20+
21+
SCOUT_DRIVER=elastic
22+
SCOUT_ELASTIC_HOST=elastic:9200

docker/laravel/app/Stubs/Car.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace App\Stubs;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
use ScoutElastic\Searchable;
8+
9+
class Car extends Model
10+
{
11+
use Searchable;
12+
13+
/**
14+
* @var string
15+
*/
16+
protected $indexConfigurator = CarIndexConfigurator::class;
17+
18+
/**
19+
* @var array
20+
*/
21+
protected $fillable = [
22+
'title'
23+
];
24+
25+
/**
26+
* @var array
27+
*/
28+
protected $mapping = [
29+
'properties' => [
30+
'title' => [
31+
'type' => 'text'
32+
],
33+
'maker' => [
34+
'type' => 'keyword'
35+
],
36+
'created_at' => [
37+
'type' => 'date',
38+
'format' => 'yyyy-MM-dd HH:mm:ss'
39+
],
40+
'updated_at' => [
41+
'type' => 'date',
42+
'format' => 'yyyy-MM-dd HH:mm:ss'
43+
]
44+
]
45+
];
46+
47+
/**
48+
* @return BelongsTo
49+
*/
50+
public function maker()
51+
{
52+
return $this->belongsTo(Maker::class);
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function toSearchableArray()
59+
{
60+
$searchableArray = $this->toArray();
61+
62+
unset($searchableArray['maker_id']);
63+
64+
$searchableArray['maker'] = $this
65+
->maker
66+
->title;
67+
68+
return $searchableArray;
69+
}
70+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Stubs;
4+
5+
use ScoutElastic\IndexConfigurator;
6+
use ScoutElastic\Migratable;
7+
8+
class CarIndexConfigurator extends IndexConfigurator
9+
{
10+
use Migratable;
11+
12+
protected $settings = [
13+
//
14+
];
15+
}

docker/laravel/app/Stubs/Maker.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Stubs;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\HasMany;
7+
8+
class Maker extends Model
9+
{
10+
/**
11+
* @var array
12+
*/
13+
protected $fillable = [
14+
'title'
15+
];
16+
17+
/**
18+
* @return HasMany
19+
*/
20+
public function cars()
21+
{
22+
return $this->hasMany(Car::class);
23+
}
24+
}

docker/laravel/database/migrations/2018_05_15_210500_create_car_models_table.php

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use App\Stubs\CarIndexConfigurator;
4+
use Illuminate\Support\Facades\Artisan;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Database\Migrations\Migration;
8+
9+
class CreateCarsTable extends Migration
10+
{
11+
/**
12+
* @inheritdoc
13+
*/
14+
public function up()
15+
{
16+
Artisan::call(
17+
'elastic:create-index',
18+
['index-configurator' => CarIndexConfigurator::class]
19+
);
20+
21+
Schema::create('cars', function (Blueprint $table) {
22+
$table->increments('id');
23+
$table->integer('maker_id');
24+
$table->string('title');
25+
$table->timestamps();
26+
});
27+
}
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
public function down()
33+
{
34+
Artisan::call(
35+
'elastic:drop-index',
36+
['index-configurator' => CarIndexConfigurator::class]
37+
);
38+
39+
Schema::dropIfExists('cars');
40+
}
41+
}

docker/laravel/database/migrations/2018_05_15_211500_create_car_makers_table.php renamed to docker/laravel/database/migrations/2018_05_15_211500_create_makers_table.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Database\Migrations\Migration;
66

7-
class CreateCarMakersTable extends Migration
7+
class CreateMakersTable extends Migration
88
{
99
/**
1010
* @inheritdoc
1111
*/
1212
public function up()
1313
{
14-
Schema::create('car_makers', function (Blueprint $table) {
14+
Schema::create('makers', function (Blueprint $table) {
1515
$table->increments('id');
1616
$table->string('title');
17+
$table->timestamps();
1718
});
1819
}
1920

@@ -22,6 +23,6 @@ public function up()
2223
*/
2324
public function down()
2425
{
25-
Schema::dropIfExists('car_makers');
26+
Schema::dropIfExists('makers');
2627
}
2728
}

docker/laravel/database/seeds/CarMakersTableSeeder.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)