Trending

#PACKAGE

Latest posts tagged with #PACKAGE on Bluesky

Latest Top
Trending

Posts tagged #PACKAGE

Laravel Query Builder v7: a must-have package for building APIs in Laravel We just released v7 of [laravel-query-builder](https://github.com/spatie/laravel-query-builder), our package that makes it easy to build flexible API endpoints. If you're building an API with Laravel, you'll almost certainly need to let consumers filter results, sort them, include relationships and select specific fields. Writing that logic by hand for every endpoint gets repetitive fast, and it's easy to accidentally expose columns or relationships you didn't intend to. Our query builder takes care of all of that. It reads query parameters from the URL, translates them into the right Eloquent queries, and makes sure only the things you've explicitly allowed can be queried. ```php // GET /users?filter[name]=John&include=posts&sort=-created_at $users = QueryBuilder::for(User::class) ->allowedFilters('name') ->allowedIncludes('posts') ->allowedSorts('created_at') ->get(); // select * from users where name = 'John' order by created_at desc ``` This major version requires PHP 8.3+ and Laravel 12 or higher, and brings a cleaner API along with some features we've been wanting to add for a while. Let me walk you through how the package works and what's new. <!--more--> ## Using the package The idea is simple: your API consumers pass query parameters in the URL, and the package translates those into the right Eloquent query. You just define what's allowed. Say you have a `User` model and you want to let API consumers filter by name. Here's all you need: ```php use Spatie\QueryBuilder\QueryBuilder; $users = QueryBuilder::for(User::class) ->allowedFilters('name') ->get(); ``` Now when someone requests `/users?filter[name]=John`, the package adds the appropriate `WHERE` clause to the query: ```sql select * from users where name = 'John' ``` Only the filters you've explicitly allowed will work. If someone tries `/users?filter[secret_column]=something`, the package throws an `InvalidFilterQuery` exception. Your database schema stays hidden from API consumers. You can allow multiple filters at once and combine them with sorting: ```php $users = QueryBuilder::for(User::class) ->allowedFilters('name', 'email') ->allowedSorts('name', 'created_at') ->get(); ``` A request to `/users?filter[name]=John&sort=-created_at` now filters by name and sorts by `created_at` descending (the `-` prefix means descending). Including relationships works the same way. If you want consumers to be able to eager-load a user's posts: ```php $users = QueryBuilder::for(User::class) ->allowedFilters('name', 'email') ->allowedIncludes('posts', 'permissions') ->allowedSorts('name', 'created_at') ->get(); ``` A request to `/users?include=posts&filter[name]=John&sort=-created_at` now returns users named John, sorted by creation date, with their posts eager-loaded. You can also select specific fields to keep your responses lean: ```php $users = QueryBuilder::for(User::class) ->allowedFields('id', 'name', 'email') ->allowedIncludes('posts') ->get(); ``` With `/users?fields=id,email&include=posts`, only the `id` and `email` columns are selected. The `QueryBuilder` extends Laravel's default Eloquent builder, so all your favorite methods still work. You can combine it with existing queries: ```php $query = User::where('active', true); $users = QueryBuilder::for($query) ->withTrashed() ->allowedFilters('name') ->allowedIncludes('posts', 'permissions') ->where('score', '>', 42) ->get(); ``` The query parameter names follow the [JSON API specification](http://jsonapi.org/) as closely as possible. This means you get a consistent, well-documented API surface without having to think about naming conventions. ## What's new in v7 ### Variadic parameters All the `allowed*` methods now accept variadic arguments instead of arrays. ```php // Before (v6) QueryBuilder::for(User::class) ->allowedFilters(['name', 'email']) ->allowedSorts(['name']) ->allowedIncludes(['posts']); // After (v7) QueryBuilder::for(User::class) ->allowedFilters('name', 'email') ->allowedSorts('name') ->allowedIncludes('posts'); ``` If you have a dynamic list, use the spread operator: ```php $filters = ['name', 'email']; QueryBuilder::for(User::class)->allowedFilters(...$filters); ``` ### Aggregate includes This is the biggest new feature. You can now include aggregate values for related models using `AllowedInclude::min()`, `AllowedInclude::max()`, `AllowedInclude::sum()`, and `AllowedInclude::avg()`. Under the hood, these map to Laravel's `withMin()`, `withMax()`, `withSum()` and `withAvg()` methods. ```php use Spatie\QueryBuilder\AllowedInclude; $users = QueryBuilder::for(User::class) ->allowedIncludes( 'posts', AllowedInclude::count('postsCount'), AllowedInclude::sum('postsViewsSum', 'posts', 'views'), AllowedInclude::avg('postsViewsAvg', 'posts', 'views'), ) ->get(); ``` A request to `/users?include=posts,postsCount,postsViewsSum` now returns users with their posts, the post count, and the total views across all posts. You can constrain these aggregates too. For example, to only count published posts: ```php use Spatie\QueryBuilder\AllowedInclude; use Illuminate\Database\Eloquent\Builder; $users = QueryBuilder::for(User::class) ->allowedIncludes( AllowedInclude::count( 'publishedPostsCount', 'posts', fn (Builder $query) => $query->where('published', true) ), AllowedInclude::sum( 'publishedPostsViewsSum', 'posts', 'views', constraint: fn (Builder $query) => $query->where('published', true) ), ) ->get(); ``` All four aggregate types support these constraint closures, making it possible to build endpoints that return computed data alongside your models without writing custom query logic. ## A perfect match for Laravel's JSON:API resources Laravel 13 is adding built-in support for [JSON:API resources](https://laravel.com/docs/master/eloquent-resources#jsonapi-resources). These new `JsonApiResource` classes handle the serialization side: they produce responses compliant with the JSON:API specification. You create one by adding the `--json-api` flag: ```bash php artisan make:resource PostResource --json-api ``` This generates a resource class where you define attributes and relationships: ```php use Illuminate\Http\Resources\JsonApi\JsonApiResource; class PostResource extends JsonApiResource { public $attributes = [ 'title', 'body', 'created_at', ]; public $relationships = [ 'author', 'comments', ]; } ``` Return it from your controller, and Laravel produces a fully compliant JSON:API response: ```json { "data": { "id": "1", "type": "posts", "attributes": { "title": "Hello World", "body": "This is my first post." }, "relationships": { "author": { "data": { "id": "1", "type": "users" } } } }, "included": [ { "id": "1", "type": "users", "attributes": { "name": "Taylor Otwell" } } ] } ``` Clients can request specific fields and includes via query parameters like `/api/posts?fields[posts]=title&include=author`. Laravel's JSON:API resources handle all of that on the response side. The [Laravel docs](https://laravel.com/docs/master/eloquent-resources#jsonapi-resources) explicitly mention our package as a companion: > Laravel's JSON:API resources handle the serialization of your responses. If you also need to parse incoming JSON:API query parameters such as filters and sorts, Spatie's Laravel Query Builder is a great companion package. So while Laravel's new JSON:API resources take care of the output format, our query builder handles the input side: parsing `filter`, `sort`, `include` and `fields` parameters from the request and translating them into the right Eloquent queries. Together they give you a full JSON:API implementation with very little boilerplate. ## In closing To upgrade from v6, check the [upgrade guide](https://github.com/spatie/laravel-query-builder/blob/main/UPGRADING.md). The changes are mostly mechanical. Check the guide for the full list. You can find the full source code and documentation [on GitHub](https://github.com/spatie/laravel-query-builder). We also have extensive [documentation](https://spatie.be/docs/laravel-query-builder/v7/introduction) on the Spatie website. This is one of the many packages we've created at [Spatie](https://spatie.be/open-source). If you want to support our open source work, consider picking up one of our [paid products](https://spatie.be/products).

🌟 Laravel Query Builder v7: a must-have package for building APIs in Laravel
#php #laravel #package #spatie #PHP

1 0 0 0
Preview
KernelSkill: A Multi-Agent Framework for GPU Kernel Optimization Improving GPU kernel efficiency is crucial for advancing AI systems. Recent work has explored leveraging large language models (LLMs) for GPU kernel generation and optimization. However, existing L…

KernelSkill: A Multi-Agent Framework for GPU Kernel Optimization

#CUDA #LLM #Performance #Package

hgpu.org?p=30665

1 0 0 0
Preview
Making LLMs Optimize Multi-Scenario CUDA Kernels Like Experts Optimizing GPU kernels manually is a challenging and time-consuming task. With the rapid development of LLMs, automated GPU kernel optimization is gradually becoming a tangible reality. However, cu…

Making LLMs Optimize Multi-Scenario CUDA Kernels Like Experts

#CUDA #Package

hgpu.org?p=30664

0 0 0 0
Preview
EvoScientist: Towards Multi-Agent Evolving AI Scientists for End-to-End Scientific Discovery The increasing adoption of Large Language Models (LLMs) has enabled AI scientists to perform complex end-to-end scientific discovery tasks requiring coordination of specialized roles, including ide…

EvoScientist: Towards Multi-Agent Evolving AI Scientists for End-to-End Scientific Discovery

#LLM #AI #Package

hgpu.org?p=30662

1 0 0 0
Post image

Showing off today’s choice in #Underwear which is a #SINNER #Jockstrap.

Anyone interested in seeing the backside?

#Package #Bulge #VPL #DickPrint #MensUnderwear #Jock #Hairy #Gay

47 2 4 0
Preview
EvoScientist: Towards Multi-Agent Evolving AI Scientists for End-to-End Scientific Discovery The increasing adoption of Large Language Models (LLMs) has enabled AI scientists to perform complex end-to-end scientific discovery tasks requiring coordination of specialized roles, including ide…

EvoScientist: Towards Multi-Agent Evolving AI Scientists for End-to-End Scientific Discovery The increasing adoption of Large Language Models (LLMs) has enabled AI scientists to perform complex end...

#Computer #science #paper #LLM #Package #Search #strategies

Origin | Interest | Match

1 0 0 0
The cart is fully assembled with graded sides, held on by cotter pins and turning latches on the corners

The cart is fully assembled with graded sides, held on by cotter pins and turning latches on the corners

11/11 Sides on!
So easy! Reqdy to rock and roll! 🤘
or my case, Get Rocks and Roll!
Gnight!
#package #unbox

0 0 1 0
along square tube handle stretches diagonally from the small D protruding  out the front of the cart

along square tube handle stretches diagonally from the small D protruding out the front of the cart

10/n pull handle and tube on! (the handle was already attached in the tow behind configuration, which is cool, but we don't have anything to tow this guy with) #package #unbox

0 0 1 0
the four wheels are mounted on the pins. Now officially a handle-less cart on its back

the four wheels are mounted on the pins. Now officially a handle-less cart on its back

wheels on! #package #unbox

1 0 0 0
two U shaped brackets are attached ti the green grate forming the base if the cart upside down

two U shaped brackets are attached ti the green grate forming the base if the cart upside down

legs on! #package #unbox

2 0 1 0
I am holding an assembly of two curved square tube metal pieces. One goes overtop the other in a large D oriented down woth two metal pins sticking out each sode for the wheels. The smaller D is inside and attached to the bottom of the other with a spring at the top of the D

I am holding an assembly of two curved square tube metal pieces. One goes overtop the other in a large D oriented down woth two metal pins sticking out each sode for the wheels. The smaller D is inside and attached to the bottom of the other with a spring at the top of the D

7/n front bracket assembled!
#package #unbox

1 0 1 0
i am holding the instruction manual in front of me overtop the pieces. the parts included page is shown

i am holding the instruction manual in front of me overtop the pieces. the parts included page is shown

6/n hmmmm 🤔 #package #unbox

2 0 2 0
four tires with black rubber and green wheels sit arrange over the middle of the rest of the pieces.

four tires with black rubber and green wheels sit arrange over the middle of the rest of the pieces.

5/n tires! #package #unbox

2 0 1 0
a grated frame side sits atop a stack of pieces with cardboard and bubble wrap between

a grated frame side sits atop a stack of pieces with cardboard and bubble wrap between

ooo! the green is nicer in person! #atlast #package #unbox

1 0 0 0
the edge flaps of the box are folded down. the bottom of the box is actually facing us, ready to be lifted away

the edge flaps of the box are folded down. the bottom of the box is actually facing us, ready to be lifted away

3/n this box has seen better days lol... the tape holding it together seems like it is 10 years old. reveal coming! #atlast #package #unbox

1 0 1 0
a fluffy tabby cat smells the now bare cardboard box

a fluffy tabby cat smells the now bare cardboard box

wrap off!
inspection #atlast
#package #unbox

1 0 0 0
a large rectangular box stretches out flat on a beige carpet. there are cat toys and cat bed beside

a large rectangular box stretches out flat on a beige carpet. there are cat toys and cat bed beside

1/n unboxing thread!
no hints just pics 😂 📦
#package #unbox

1 0 1 0
Post image

APTUI Introduces a Modern TUI for Debian, Ubuntu, and Mint Packages APTUI is a new open-source terminal UI that simplifies APT package management for Debian, Ubuntu, and Linux Mint users.

#Software #Linux #& #Open #Source #News #apt #package #manager

Origin | Interest | Match

0 0 0 0
Post image

APTUI Introduces a Modern TUI for Debian, Ubuntu, and Mint Packages APTUI is a new open-source terminal UI that simplifies APT package management for Debian, Ubuntu, and Linux Mint users.

#Software #Linux #& #Open #Source #News #apt #package #manager

Origin | Interest | Match

0 0 0 0

My new project, commercial illustration
www.behance.net/gallery/2451...

#cat #design #beautybranding #mascot #branding #package #logo

2 0 0 0
Post image Post image Post image Post image

Getting at it early today and showing off today’s choice in #Underwear.

#BoxMenswear #BoxUnderwear #MensUnderwear #MensBriefs #Briefs #Gay #Bulge #Package #VPL #DickPrint #Hairy #HairyMan #HairyGay

50 1 1 0
Post image

AECOM wins 3 contracts on $1B #Seattle light-rail work #package www.constructiondive.com/news/aecom-s...

2 0 0 0
Post image

How about we get back to some regular programming?

Showing off today’s choice in #Underwear.

#SINNER #Gay #MensUnderwear #MensBriefs #Briefs #Bulge #Package #VPL #DickPrint #GayMan

@sinnerwear.bsky.social

48 1 1 0