Code feed
Code worth pausing your scroll for.
Filter your feed
Community signal
ShuffleDispatch many jobs with Bus bulk
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/framework/docs/changelog#introduce-busbulk
Dispatch many jobs with Bus bulk
<?php
use Illuminate\Support\Facades\Bus;
Bus::bulk(
$users
->map(fn (User $user) => new RefreshProfile($user))
->all(),
);
// Further reading: https://laravel.com/framework/docs/changelog#introduce-busbulk
Read filled request enums safely
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/framework/docs/changelog#add-whenfilledenum-method-to-interactswithdata
Read filled request enums safely
<?php
$request->whenFilledEnum(
'status',
OrderStatus::class,
fn (OrderStatus $status) => $query->where('status', $status),
);
// Further reading: https://laravel.com/framework/docs/changelog#add-whenfilledenum-method-to-interactswithdata
Attach structured metadata to routes
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/framework/docs/changelog#add-route-metadata-support
Attach structured metadata to routes
<?php
Route::get('/pricing', PricingController::class)
->metadata([
'seo' => ['title' => 'Pricing', 'robots' => 'index'],
'feature' => 'public-pricing',
]);
$title = request()->route()->getMetadata('seo.title');
// Further reading: https://laravel.com/framework/docs/changelog#add-route-metadata-support
Extend a cache item without reading it
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/cache#extending-item-lifetime
Extend a cache item without reading it
<?php
use Illuminate\Support\Facades\Cache;
$extended = Cache::touch(
"checkout:{$cart->id}",
now()->addMinutes(30),
);
// Further reading: https://laravel.com/docs/13.x/cache#extending-item-lifetime
Configure queued jobs with attributes
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/releases#expanded-php-attributes
Configure queued jobs with attributes
<?php
use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\Timeout;
use Illuminate\Queue\Attributes\Tries;
#[Tries(5)]
#[Backoff(10, 30, 90)]
#[Timeout(120)]
final class SyncInventory implements ShouldQueue
{
// ...
}
// Further reading: https://laravel.com/docs/13.x/releases#expanded-php-attributes
Secure controllers with attributes
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/releases#expanded-php-attributes
Secure controllers with attributes
<?php
use Illuminate\Routing\Attributes\Controllers\Authorize;
use Illuminate\Routing\Attributes\Controllers\Middleware;
#[Middleware('auth')]
final class InvoiceController
{
#[Authorize('view', 'invoice')]
public function show(Invoice $invoice): Invoice
{
return $invoice;
}
}
// Further reading: https://laravel.com/docs/13.x/releases#expanded-php-attributes
Route job classes centrally
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/queues#queue-routing
Route job classes centrally
<?php
use App\Jobs\GenerateReport;
use Illuminate\Support\Facades\Queue;
Queue::route(
GenerateReport::class,
connection: 'redis',
queue: 'reports',
);
// Further reading: https://laravel.com/docs/13.x/queues#queue-routing
Return a JSON:API resource
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/eloquent-resources#json-api-resources
Return a JSON:API resource
<?php
use Illuminate\Http\Resources\JsonApi\JsonApiResource;
final class PostResource extends JsonApiResource
{
public $attributes = ['title', 'body', 'created_at'];
public $relationships = ['author', 'comments'];
}
return $post->toResource();
// Further reading: https://laravel.com/docs/13.x/eloquent-resources#json-api-resources
Search by semantic similarity
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/releases#semantic-vector-search
Search by semantic similarity
<?php
use Illuminate\Support\Facades\DB;
$articles = DB::table('articles')
->whereVectorSimilarTo('embedding', $query)
->limit(8)
->get();
// Further reading: https://laravel.com/docs/13.x/releases#semantic-vector-search
Generate and cache embeddings
Laravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/ai-sdk#embeddings
Generate and cache embeddings
<?php
use Illuminate\Support\Str;
$embedding = Str::of($article->body)
->toEmbeddings(cache: 3600);
// Further reading: https://laravel.com/docs/13.x/ai-sdk#embeddings