Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

guillaumebriday/laravel-blog

1797 stars
4 code files
View guillaumebriday/laravel-blog on GitHub

app/Helpers/date.php

Open in GitHub
use Illuminate\Support\Carbon;
 
function carbon(string $parseString = '', string $tz = null): Carbon
{
return new Carbon($parseString, $tz);
}

app/Models/User.php

Open in GitHub
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
 
class User extends Authenticatable implements MustVerifyEmail
{
public function scopeLastWeek(Builder $query): Builder
{
return $query->whereBetween('registered_at', [carbon('1 week ago'), now()])
->latest();
}
}

tests/Unit/PostTest.php

Open in GitHub
use App\Models\Post;
use Tests\TestCase;
 
class PostTest extends TestCase
{
public function testGettingOnlyLastWeekPosts()
{
Post::factory()
->count(3)
->create()
->each(function ($post) use ($faker) {
$post->posted_at = $faker->dateTimeBetween(carbon('3 months ago'), carbon('2 months ago'));
$post->save();
});
Post::factory()
->count(3)
->create()
->each(function ($post) use ($faker) {
$post->posted_at = $faker->dateTimeBetween(carbon('1 week ago'), now());
$post->save();
});
}
}

composer.json

Open in GitHub
{
"name": "guillaumebriday/laravel-blog",
"require": {
"php": "^7.4",
"barryvdh/laravel-debugbar": "3.5.1",
"doctrine/dbal": "2.11.1",
// ...
},
"autoload": {
"files": [
"app/Helpers/date.php"
]
},
 
// ... other settings
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.