Skip to content

Commit 7c5422d

Browse files
authored
Allow custom migrations (#24)
1 parent 941a430 commit 7c5422d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Instead of adding ``` ShortUrl::routes(); ``` you can call three separates metho
3838

3939
this allows you to add middlewares or prefix routes.
4040

41+
### Migration Customization
42+
43+
If you are not going to use Short Url's default migrations, you should call the
44+
`ShortUrl::ignoreMigrations();` method in the `register` method of your `AppServiceProvider`.
45+
You may export the default migrations using
46+
47+
```
48+
php artisan vendor:publish --tag=shorturl-migrations
49+
```
50+
4151
## Nice!
4252

4353
Laravel short url is now set up on your homepage.

src/ShortUrl.php

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
class ShortUrl
66
{
7+
/**
8+
* Indicates if migrations will be run.
9+
*
10+
* @var bool
11+
*/
12+
public static $runsMigrations = true;
13+
714
/**
815
* Register the routes to create urls.
916
*
@@ -49,4 +56,14 @@ public function routes()
4956
$this->manageRoutes();
5057
$this->redirectRoute();
5158
}
59+
60+
/**
61+
* Configure package to not register its migrations.
62+
*
63+
* @return static
64+
*/
65+
public static function ignoreMigrations()
66+
{
67+
static::$runsMigrations = false;
68+
}
5269
}

src/ShortUrlServiceProvider.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public function boot()
1818
$this->loadViewsFrom(__DIR__.'/../resources/views', 'shorturl');
1919

2020
if ($this->app->runningInConsole()) {
21-
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
21+
$this->registerMigrations();
22+
23+
$this->publishes([
24+
__DIR__.'/../database/migrations' => database_path('migrations'),
25+
], 'shorturl-migrations');
2226

2327
$this->publishes([
2428
__DIR__.'/../config/shorturl.php' => config_path('shorturl.php'),
@@ -34,6 +38,18 @@ public function boot()
3438
}
3539
}
3640

41+
/**
42+
* Register migration files.
43+
*
44+
* @return void
45+
*/
46+
protected function registerMigrations()
47+
{
48+
if (ShortUrl::$runsMigrations) {
49+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
50+
}
51+
}
52+
3753
/**
3854
* Register the application services.
3955
*

0 commit comments

Comments
 (0)