Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update migration stub and existing migrations to use anonymous class #2406

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions docs/content/1_docs/3_modules/12_nested-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ Route::get('{slug}', function ($slug) {
})->where('slug', '.*');
```

For more information on how to work with nested items in your application, you can refer to the
For more information on how to work with nested items in your application, you can refer to the
[laravel-nestedset package documentation](https://github.com/lazychaser/laravel-nestedset#retrieving-nodes).

### Setting a maximum nested depth

You can also define the maximum depth allowed for the module changing the following:
```php
```php
protected $nestedItemsDepth = 1;
```
Note: a depth of 1 means parent and child.
Expand All @@ -100,23 +100,20 @@ We'll use the `slug` and `position` features in this example but you can customi

```
php artisan twill:make:module issues -SP
php artisan twill:make:module issueArticles -SP --parentModel=Issue
php artisan twill:make:module issueArticles -SP --parentModel=Issue
```

Add the `issue_id` foreign key to the child module's migration:

```php
class CreateIssueArticlesTables extends Migration
public function up()
{
public function up()
{
Schema::create('issue_articles', function (Blueprint $table) {
// ...
$table->foreignIdFor(Issue::class);
});

Schema::create('issue_articles', function (Blueprint $table) {
// ...
}
$table->foreignIdFor(Issue::class);
});

// ...
}
```

Expand All @@ -137,7 +134,7 @@ class IssueArticle extends Model implements Sortable
// ...
'issue_id',
];

public function issue()
{
return $this->belongsTo(Issue::class);
Expand Down
23 changes: 9 additions & 14 deletions docs/content/1_docs/4_form-fields/11_repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,16 @@ php artisan twill:make:module TeamMember -P
relationship:

```php
class CreateTeamMembersTables extends Migration
public function up()
{
public function up()
{
Schema::create('team_members', function (Blueprint $table) {
/* ... */

$table->foreignId('team_id')
->constrained()
->onUpdate('cascade')
->onDelete('cascade');
});
}
Schema::create('team_members', function (Blueprint $table) {
/* ... */

$table->foreignId('team_id')
->constrained()
->onUpdate('cascade')
->onDelete('cascade');
});
}
```

Expand Down Expand Up @@ -306,5 +303,3 @@ of the repeater items. This directive also accepts a `hidePrefix` option to hide
:required="true"
/>
```


6 changes: 3 additions & 3 deletions docs/content/1_docs/7_media-library/05_custom-metadata.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Custom metadata

By default, media comes with a few metadata attributes that can be filled in from the media managers:
By default, media comes with a few metadata attributes that can be filled in from the media managers:
Tags, Alt text and caption.

Say we want to add more metadata, some of which might be translatable. To do this we have to go through a few
Expand Down Expand Up @@ -41,7 +41,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddFieldsToMedia extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -58,7 +58,7 @@ class AddFieldsToMedia extends Migration
$table->dropColumn('attribution');
});
}
}
};
```

And that is all. The most important part is to make sure your migration fields are named the same as your custom metadata values in the twill config.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ We can see that `Route::module('pages');` has been added to `routes/twill.php`.

This is automatic, because it is simple enough to do.

The `routes/twill.php` file is a Twill specific list of routes. These routes are protected and loaded specifically for
The `routes/twill.php` file is a Twill specific list of routes. These routes are protected and loaded specifically for
the CMS.

In standard Laravel there is no `module` method on a `Route` object, this is something Twill provides and it will build
Expand All @@ -139,7 +139,7 @@ many routes for your module, these are then used by the cms, controllers and req

The second step, we have to do ourself. So let's open `app/Providers/AppServiceProvider.php`.

We will not go into detail about what a service provider is, for that you can check the
We will not go into detail about what a service provider is, for that you can check the
[official documentation](https://laravel.com/docs/10.x/providers).

In our `boot` method we will add the suggested snippet:
Expand Down Expand Up @@ -214,14 +214,14 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePagesTables extends Migration
return new class extends Migration
{
public function up()
{
Schema::create('pages', function (Blueprint $table) {
// this will create an id, a "published" column, and soft delete and timestamps columns
createDefaultTableFields($table);

// add those 2 columns to enable publication timeframe fields
// (you can use publish_start_date only if you don't need to provide the ability to specify an end date)
// $table->timestamp('publish_start_date')->nullable();
Expand Down Expand Up @@ -250,7 +250,7 @@ class CreatePagesTables extends Migration
Schema::dropIfExists('page_slugs');
Schema::dropIfExists('pages');
}
}
};
```

This file will create the minimum required tables and columns that Twill uses to provide the CMS functionality. Later in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMenuLinksTables extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -83,7 +83,7 @@ class CreateMenuLinksTables extends Migration
{
Schema::dropIfExists('menu_links');
}
}
};
```

Now you can run the migration: `php artisan migrate`
Expand Down Expand Up @@ -223,7 +223,7 @@ use App\Models\MenuLink;
class MenuLinkRepository extends ModuleRepository
{
protected $relatedBrowsers = ['page'];

use HandleNesting;

public function __construct(MenuLink $model)
Expand Down Expand Up @@ -367,7 +367,7 @@ We will change the contents of `resources/views/components/menu.blade.php` to th
```

We add just a minimal amount of styling as we will not spend too much time on that during this guide. But this will
build a navigation tree that is slightly indented so that you can see the proper structure.
build a navigation tree that is slightly indented so that you can see the proper structure.

You cannot see it in action yet, for that we have to add the component to the main template file.

Expand All @@ -389,7 +389,7 @@ But, for this guide, we will simply open `resources/views/site/page.blade.php` a
</head>
<body>
<x-menu/> <!-- [tl! ++] -->
<div class="mx-auto max-w-2xl">
<div class="max-w-2xl mx-auto">
{!! $item->renderBlocks() !!}
</div>
</body>
Expand All @@ -402,4 +402,3 @@ Wherever you will put `<x-menu/>` it will render the menu. That's useful because
Now that we have pages and a menu, we have one last thing we need to do.

[We need a frontpage](./10_setup-the-frontpage.md)!

4 changes: 2 additions & 2 deletions docs/content/2_guides/json_repeaters/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProjectsTables extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -20,4 +20,4 @@ public function down()
{
Schema::dropIfExists('projects');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateProfilesTables extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -27,4 +27,4 @@ public function down()
{
Schema::dropIfExists('profiles');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateArticlesTables extends Migration
return new class extends Migration
{
public function up()
{
Expand Down Expand Up @@ -31,4 +31,4 @@ public function down()
Schema::dropIfExists('article_slugs');
Schema::dropIfExists('articles');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProjectsTables extends Migration
return new class extends Migration
{
public function up(): void
{
Expand Down Expand Up @@ -34,4 +34,4 @@ public function down(): void
Schema::dropIfExists('project_slugs');
Schema::dropIfExists('projects');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePartnersTables extends Migration
return new class extends Migration
{
public function up(): void
{
Expand Down Expand Up @@ -44,4 +44,4 @@ public function down(): void
Schema::dropIfExists('partner_slugs');
Schema::dropIfExists('partners');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCommentsTables extends Migration
return new class extends Migration
{
public function up(): void
{
Expand All @@ -21,4 +21,4 @@ public function down(): void
{
Schema::dropIfExists('comments');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateLinksTables extends Migration
return new class extends Migration
{
public function up(): void
{
Expand All @@ -23,4 +23,4 @@ public function down(): void
{
Schema::dropIfExists('links');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateWritersTablesForBrowsers extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -23,4 +23,4 @@ public function down()
Schema::dropIfExists('writer_revisions');
Schema::dropIfExists('writers');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateLettersTablesForBrowsers extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -23,4 +23,4 @@ public function down()
Schema::dropIfExists('letter_revisions');
Schema::dropIfExists('letters');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateLetterWriterTableForBrowsers extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -19,4 +19,4 @@ public function down()
{
Schema::dropIfExists('letter_writer');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateBiosTablesForBrowsers extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -25,4 +25,4 @@ public function down()
Schema::dropIfExists('bio_revisions');
Schema::dropIfExists('bios');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateBooksTablesForBrowsers extends Migration
return new class extends Migration
{
public function up()
{
Expand All @@ -23,4 +23,4 @@ public function down()
Schema::dropIfExists('book_revisions');
Schema::dropIfExists('books');
}
}
};
Loading
Loading