Skip to content

Commit 5cf7465

Browse files
Add vendor publish as well as register make:fm-model command
1 parent 2a7163f commit 5cf7465

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ Install `gearbox-solutions/eloquent-filemaker` in your project using Composer.
3737
```
3838
composer require gearbox-solutions/eloquent-filemaker
3939
```
40+
41+
## Vendor Publish
42+
This package adds 2 optional vendor publishes that will create a model stub for you that you can customize.
43+
```shell
44+
php artisan vendor:publish --tag=eloquent-filemaker-stubs
45+
// or
46+
php artisan vendor:publish --provider="GearboxSolutions\EloquentFileMaker\Providers\FileMakerConnectionServiceProvider"
47+
```
48+
This publish is best if you are looking to have a mix of FileMaker backed models and another DB backed model.
49+
50+
```shell
51+
php artisan vendor:publish --tag=eloquent-filemaker-override-model
52+
```
53+
This publish will create a `model.stub` that will be used by `php artisan make:model` to set up new models. You should use this on projects that will only have models backed by FileMaker.
54+
55+
## Alternatively, use new make command
56+
Alternatively, you can use the new `make:fm-model` command. All options available to Laravel's native `make:model` command are also available to `make:fm-model` command.
57+
58+
```shell
59+
php artisan make:fm-model Model
60+
```
61+
4062
# Usage
4163
With the package installed you can now have access to all the features of this package. There are a few different areas to configure.
4264

src/Commands/FMModelMakeCommand.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace GearboxSolutions\EloquentFileMaker\Commands;
4+
5+
use Illuminate\Foundation\Console\ModelMakeCommand as LaravelModelMakeCommand;
6+
use Illuminate\Support\Str;
7+
use Symfony\Component\Console\Input\InputOption;
8+
9+
class FMModelMakeCommand extends LaravelModelMakeCommand {
10+
11+
protected $name = 'make:fm-model';
12+
13+
/**
14+
* The console command description.
15+
*
16+
* @var string
17+
*/
18+
protected $description = 'Create a new Eloquent FileMaker model class';
19+
20+
public function handle()
21+
{
22+
parent::handle();
23+
24+
$this->input->setOption('filemaker', true);
25+
}
26+
27+
public function getStub()
28+
{
29+
$stub = parent::getStub();
30+
31+
if($this->option('filemaker')) {
32+
$stub = Str::replace('/model.', '/fm.model.', $stub);
33+
34+
throw_if(!file_exists($stub), new \RuntimeException("This model type is not yet supported by Eloquent FileMaker."));
35+
}
36+
37+
return $stub;
38+
}
39+
40+
protected function getOptions()
41+
{
42+
return array_merge(parent::getOptions(), [
43+
['filemaker', null, InputOption::VALUE_NONE, 'Use the FileMaker stub instead of base model stub'],
44+
]);
45+
}
46+
}

src/Commands/stubs/fm.model.stub

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use GearboxSolutions\EloquentFileMaker\Database\Eloquent\FMModel;
7+
8+
class {{ class }} extends FMModel
9+
{
10+
use HasFactory;
11+
}

src/Providers/FileMakerConnectionServiceProvider.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace GearboxSolutions\EloquentFileMaker\Providers;
44

5+
use GearboxSolutions\EloquentFileMaker\Commands\FMModelMakeCommand;
56
use GearboxSolutions\EloquentFileMaker\Services\FileMakerConnection;
7+
use Illuminate\Foundation\Console\ModelMakeCommand as LaravelModelMakeCommand;
68
use Illuminate\Support\ServiceProvider;
79

810
class FileMakerConnectionServiceProvider extends ServiceProvider
@@ -33,6 +35,12 @@ public function register()
3335
$this->app->bind(FileMakerConnection::class, function ($app) {
3436
return $app['fm.connection'];
3537
});
38+
39+
if ($this->app->runningInConsole()) {
40+
$this->commands([
41+
FMModelMakeCommand::class,
42+
]);
43+
}
3644
}
3745

3846
/**
@@ -42,6 +50,12 @@ public function register()
4250
*/
4351
public function boot()
4452
{
45-
//
53+
$this->publishes([
54+
__DIR__.'/../Commands/stubs/fm.model.stub' => base_path('stubs/model.stub')
55+
], 'eloquent-filemaker-override-model');
56+
57+
$this->publishes([
58+
__DIR__.'/../Commands/stubs/fm.model.stub' => base_path('stubs/fm.model.stub')
59+
], 'eloquent-filemaker-stubs');
4660
}
4761
}

0 commit comments

Comments
 (0)