Skip to content

Commit 648ee0f

Browse files
Add vendor publish as well as register make:fm-model command
1 parent c2271d2 commit 648ee0f

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ Install `gearbox-solutions/eloquent-filemaker` in your project using Composer.
5959
```
6060
composer require gearbox-solutions/eloquent-filemaker
6161
```
62+
63+
## Vendor Publish
64+
This package adds 2 optional vendor publishes that will create a model stub for you that you can customize.
65+
```shell
66+
php artisan vendor:publish --tag=eloquent-filemaker-stubs
67+
// or
68+
php artisan vendor:publish --provider="GearboxSolutions\EloquentFileMaker\Providers\FileMakerConnectionServiceProvider"
69+
```
70+
This publish is best if you are looking to have a mix of FileMaker backed models and another DB backed model.
71+
72+
```shell
73+
php artisan vendor:publish --tag=eloquent-filemaker-override-model
74+
```
75+
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.
76+
77+
## Alternatively, use new make command
78+
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.
79+
80+
```shell
81+
php artisan make:fm-model Model
82+
```
83+
6284
# Usage
6385
With the package installed you can now have access to all the features of this package. There are a few different areas to configure.
6486

src/Commands/FMModelMakeCommand.php

Lines changed: 46 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace GearboxSolutions\EloquentFileMaker\Providers;
44

55
use GearboxSolutions\EloquentFileMaker\Middleware\EndSession;
6+
use GearboxSolutions\EloquentFileMaker\Commands\FMModelMakeCommand;
67
use GearboxSolutions\EloquentFileMaker\Services\FileMakerConnection;
78
use Illuminate\Contracts\Http\Kernel;
9+
use Illuminate\Foundation\Console\ModelMakeCommand as LaravelModelMakeCommand;
810
use Illuminate\Support\ServiceProvider;
911

1012
class FileMakerConnectionServiceProvider extends ServiceProvider
@@ -38,6 +40,11 @@ public function register()
3840

3941
app('router')->aliasMiddleware('fm.end-session', EndSession::class);
4042

43+
if ($this->app->runningInConsole()) {
44+
$this->commands([
45+
FMModelMakeCommand::class,
46+
]);
47+
}
4148
}
4249

4350
/**
@@ -49,5 +56,16 @@ public function boot(Kernel $kernel)
4956
{
5057
// add the middleware to the global middleware so that we always end the FileMaker session
5158
$kernel->pushMiddleware(EndSession::class);
59+
60+
$this->publishes([
61+
__DIR__ . '/../config/eloquent-filemaker.php' => config_path('eloquent-filemaker.php'),
62+
], 'eloquent-filemaker-config');
63+
$this->publishes([
64+
__DIR__.'/../Commands/stubs/fm.model.stub' => base_path('stubs/model.stub')
65+
], 'eloquent-filemaker-override-model');
66+
67+
$this->publishes([
68+
__DIR__.'/../Commands/stubs/fm.model.stub' => base_path('stubs/fm.model.stub')
69+
], 'eloquent-filemaker-stubs');
5270
}
5371
}

0 commit comments

Comments
 (0)