diff --git a/README.md b/README.md
index 855cc00..3fea02c 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,13 @@ ALWAYS use strict comparison (=== and !==). If needed, cast things go the correc
Also consider enabling strict types in your code. This will prevent passing variables of wrong data types to functions
```
-The `slug` matches the file name, the `author_username` is the Twitter handle of the tip author, `tweet_id` is the id of the tweet with the tip, and `images` is an array of images that should be shown between the heading and the content.
+The `slug` matches the file name, the `author_username` is the Twitter handle of the tip author, `tweet_id` is the id of the tweet with the tip, and `images` is an array of images that should be shown between the heading and the content.'
+
+**Make sure you also create a record in `content/users` for your Twitter handle** if your Author is not created yet. The tip's `author_username` needs to reference an Author model.
+
+### Helper command
+
+You can also use the `php artisan tweet:add` command to add content, just make sure that the tweet's "dependencies" (author and possibly thread) are in place.
## Local setup
diff --git a/app/Console/Commands/AddTweet.php b/app/Console/Commands/AddTweet.php
new file mode 100644
index 0000000..debbef3
--- /dev/null
+++ b/app/Console/Commands/AddTweet.php
@@ -0,0 +1,35 @@
+argument('tweet'))->afterLast('/')->before('?');
+
+ $this->line('Fetching tweet ID ' . $id);
+
+ $tip = Tip::fromTweet(
+ $tweet = Tweet::fetch($id)
+ );
+
+ $tip->slug = $this->ask('Slug', $tip->defaultSlug());
+
+ $tip->thread_slug = $this->choice('Thread', Thread::all()->pluck('slug', 'title')->prepend('- None - ', null)->toArray(), null);
+
+ $tip->save();
+
+ $this->info("Successfully saved tip to: content/tips/{$tip->slug}.md");
+ }
+}
diff --git a/app/Models/Thread.php b/app/Models/Thread.php
index 926fb6f..2a13090 100644
--- a/app/Models/Thread.php
+++ b/app/Models/Thread.php
@@ -32,7 +32,7 @@ class Thread extends Model
$table->string('slug')->unique();
$table->string('title');
$table->string('tweet_id')->nullable();
- $table->foreignId('author_username')->constrained('authors', 'username');
+ $table->foreignId('author_username')->nullable()->constrained('authors', 'username');
$table->text('content');
$table->json('links')->default('{}');
$table->timestamp('created_at');
@@ -58,7 +58,7 @@ class Thread extends Model
if (is_numeric($this->tweet_id)) {
return "https://twitter.com/{$this->author_username}/status/{$this->tweet_id}";
}
-
+
return $this->tweet_id;
}
diff --git a/app/Models/Tip.php b/app/Models/Tip.php
index 7b55074..10cde5b 100644
--- a/app/Models/Tip.php
+++ b/app/Models/Tip.php
@@ -19,7 +19,7 @@ use Illuminate\Support\Str;
* @property string $content
* @property string $tweet_id
* @property string $author_username
- * @property string|null $thread_id
+ * @property string|null $thread_slug
* @property string[] $images
* @property-read Author $author
* @property-read Thread|null $thread
@@ -41,7 +41,7 @@ class Tip extends Model
$table->string('slug')->unique();
$table->string('title');
$table->string('tweet_id');
- $table->foreignId('thread_slug')->constrained('threads', 'slug')->nullable();
+ $table->foreignId('thread_slug')->nullable();
$table->foreignId('author_username')->constrained('authors', 'username');
$table->json('images')->default('[]');
$table->timestamp('created_at');
@@ -74,7 +74,7 @@ class Tip extends Model
'title' => (string) Str::of(Str::of($tweet->text)->explode("\n")->first())->rtrim('.')->replaceMatches('/^([^a-zA-Z]*)/', ''), // remove any non-ascii characters from the beginning
'content' => (string) Str::of($tweet->text)->explode("\n")->skip(1)->join("\n"),
'tweet_id' => $tweet->id,
- 'thread_slug' => $threadSlug ?? Thread::firstWhere('tweet_id', $tweet->threadId)->slug,
+ 'thread_slug' => $threadSlug ?? Thread::firstWhere('tweet_id', $tweet->threadId)?->slug,
'author_username' => Author::firstOrCreate([
'username' => $tweet->author->username,
'name' => $tweet->author->name,
@@ -89,7 +89,7 @@ class Tip extends Model
{
static::creating(function (self $model) {
$model->created_at ??= now();
- $model->slug ??= Str::slug($model->title);
+ $model->slug ??= $this->defaultSlug();
});
static::addGlobalScope('order', fn (Builder $query) => $query->orderBy('created_at', 'desc'));
@@ -104,4 +104,9 @@ class Tip extends Model
{
return false;
}
+
+ public function defaultSlug(): string
+ {
+ return Str::slug($this->title);
+ }
}
diff --git a/content/authors/archtechx.md b/content/authors/archtechx.md
index c6326c7..100e607 100644
--- a/content/authors/archtechx.md
+++ b/content/authors/archtechx.md
@@ -1,5 +1,5 @@
---
username: archtechx
-name: 'ARCHTECH'
+name: ARCHTECH
avatar: 'https://pbs.twimg.com/profile_images/1393303364390227974/uaP8Hoq1_normal.jpg'
---
diff --git a/content/threads/pest-tips.md b/content/threads/pest-tips.md
index bd55ee7..065e550 100644
--- a/content/threads/pest-tips.md
+++ b/content/threads/pest-tips.md
@@ -4,4 +4,5 @@ title: 'Pest Tips'
tweet_id: 1427310302656438274
author_username: archtechx
created_at: 2021-08-16T19:09:23+02:00
+links: {}
---
diff --git a/content/tips/create-a-using-helper-in-pest.md b/content/tips/create-a-using-helper-in-pest.md
new file mode 100644
index 0000000..a960a83
--- /dev/null
+++ b/content/tips/create-a-using-helper-in-pest.md
@@ -0,0 +1,12 @@
+---
+title: 'Another pest tip: Create a using() helper to get perfect IDE support on $this calls inside your tests'
+tweet_id: '1426219050250772482'
+thread_slug: 'Pest Tips'
+author_username: archtechx
+images:
+ - 'https://pbs.twimg.com/media/E8ryqTuWEAQT-1H.jpg'
+created_at: 2021-08-16T19:07:26+02:00
+slug: create-a-using-helper-in-pest
+---
+
+Out of the box, @pestphp has amazing IDE support for the expect()->toBe() syntax, but sometimes you need to use $this — usually for things like HTTP calls.
diff --git a/content/tips/create-a-using-helper.md b/content/tips/create-a-using-helper.md
deleted file mode 100644
index fb9de58..0000000
--- a/content/tips/create-a-using-helper.md
+++ /dev/null
@@ -1,11 +0,0 @@
----
-title: 'Create a using() helper'
-tweet_id: 1426219050250772482
-thread_slug: pest-tips
-author_username: archtechx
-images:
- - https://pbs.twimg.com/media/E8ryqTuWEAQT-1H.jpg
-created_at: 2021-08-16T19:09:24+02:00
-slug: create-a-using-helper
----
-Create a using() helper to get perfect IDE support on $this calls inside your tests.
diff --git a/content/tips/create-helper-functions-for-creating-models-in-tests-using-factories.md b/content/tips/create-helper-functions-for-creating-models-in-tests-using-factories.md
index 812e63a..45d6347 100644
--- a/content/tips/create-helper-functions-for-creating-models-in-tests-using-factories.md
+++ b/content/tips/create-helper-functions-for-creating-models-in-tests-using-factories.md
@@ -5,8 +5,7 @@ thread_slug: pest-tips
author_username: archtechx
images:
- https://pbs.twimg.com/media/E8mO3a5VEAAsjr1.jpg
-
-created_at: 2021-08-16T19:09:22+02:00
+created_at: 2021-08-16T19:07:22+02:00
slug: create-helper-functions-for-creating-models-in-tests-using-factories
---
For example:
diff --git a/content/tips/disable-livewire-polling-when-an-element-is-hidden.md b/content/tips/disable-livewire-polling-when-an-element-is-hidden.md
deleted file mode 100644
index a6335ad..0000000
--- a/content/tips/disable-livewire-polling-when-an-element-is-hidden.md
+++ /dev/null
@@ -1,12 +0,0 @@
----
-title: 'Disable Livewire polling when an element is hidden'
-tweet_id: '1383079668358725636'
-thread_slug: ''
-author_username: abrardev99
-images:
- - 'https://i.ibb.co/zZ7rNn8/Livewire-polling.png'
-created_at: 2021-04-16T17:20:27+02:00
-slug: disable-livewire-polling-when-an-element-is-hidden
----
-
-Livewire (v2.4.3) landed a new polling modifier that lets you limit polling when an element is not visible in the current viewport.
diff --git a/resources/views/components/feed.blade.php b/resources/views/components/feed.blade.php
index e1f6f89..59e9ee2 100644
--- a/resources/views/components/feed.blade.php
+++ b/resources/views/components/feed.blade.php
@@ -29,7 +29,7 @@
@if ($tip->images())
@foreach ($tip->images() as $image)
-
+
@endforeach
@endif
diff --git a/resources/views/tips/show.blade.php b/resources/views/tips/show.blade.php
index b75a533..c940fed 100644
--- a/resources/views/tips/show.blade.php
+++ b/resources/views/tips/show.blade.php
@@ -60,7 +60,7 @@
@if ($tip->images())
@foreach ($tip->images() as $image)
+ src="{{ $image->large() }}" alt="{{ $tip->title }}">
@endforeach
@endif