Code feed
Code worth pausing your scroll for.
Filter your feed
Community signal
ShuffleBuild conditional queries fluently
Original CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks
Build conditional queries fluently
<?php
$users = User::query()
->when($role, fn ($query, $role) =>
$query->where('role', $role)
)
->latest()
->get();
// Further reading: https://laravel-news.com/eloquent-tips-tricks
Build multi-type JSON schemas
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/framework/docs/changelog#add-multi-type-union-support-to-illuminatejsonschema
Build multi-type JSON schemas
<?php
use Illuminate\JsonSchema\JsonSchema;
$identifier = JsonSchema::union([
'string',
'number',
])->nullable();
// Further reading: https://laravel.com/framework/docs/changelog#add-multi-type-union-support-to-illuminatejsonschema
Save without touching timestamps
Original CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks
Save without touching timestamps
<?php
$product->forceFill([
'updated_at' => '2025-01-01 10:00:00',
]);
$product->save(['timestamps' => false]);
// Further reading: https://laravel-news.com/eloquent-tips-tricks
Extend the new Artisan dev runner
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/framework/docs/changelog#add-artisan-dev-command
Extend the new Artisan dev runner
<?php
use Illuminate\Foundation\Console\DevCommands;
DevCommands::artisan('reverb:start', 'reverb')->orange();
DevCommands::register(
'stripe listen --forward-to '.config('app.url'),
'stripe',
)->green();
// Start everything with: php artisan dev
// Further reading: https://laravel.com/framework/docs/changelog#add-artisan-dev-command
Process big tables in chunks
Original CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks
Process big tables in chunks
<?php
User::query()->chunkById(500, function ($users): void {
foreach ($users as $user) {
SyncProfile::dispatch($user);
}
});
// Further reading: https://laravel-news.com/eloquent-tips-tricks
Bb
Jjjjj;
Hello, CodeSnap!
const greet = name => {
return `Hello, ${name}!`;
};
console.log(greet('developer'));
Hello, CodeSnap!
const greet = name => {
return `Hello, ${name}!`;
};
console.log(greet('developer'));
Constrain relationships once
Original CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks
Constrain relationships once
<?php
public function publishedPosts(): HasMany
{
return $this->hasMany(Post::class)
->whereNotNull('published_at')
->latest('published_at');
}
// Further reading: https://laravel-news.com/eloquent-tips-tricks
You’re all caught up.