tobyselway
tobyselway
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
My goal is to write a simple Eloquent-compatible query builder that relays info about what is being queried to the user so they can get their data from wherever they want
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Still a long way to go, but the basic concept seems to work. These are the StaticModel and StaticBuilder classes I wrote:
class StaticModel extends Model {
protected $guarded = [];
}

class StaticBuilder extends Builder
{
protected array $items;

public function __construct(array $items = [])
{
$this->items = $items;
}

public function orderBy($column, $direction = 'asc') {
// TODO: Pass params to provider
return $this;
}

public function where($column, $operator = null, $value = null, $boolean = 'and')
{
if ($column instanceof Closure && is_null($operator)) {
$column($this);
} else {
// TODO: Pass params to provider
dump(["where", $column, $operator, $value, $boolean]);
}
return $this;
}

public function get($columns = ['*'])
{
// TODO: Pass params to provider
return collect($this->items);
}

public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
return new LengthAwarePaginator($this->items, sizeof($this->items), $perPage);
}

public function getModel()
{
return new StaticModel;
}

public function __clone() {}
}
class StaticModel extends Model {
protected $guarded = [];
}

class StaticBuilder extends Builder
{
protected array $items;

public function __construct(array $items = [])
{
$this->items = $items;
}

public function orderBy($column, $direction = 'asc') {
// TODO: Pass params to provider
return $this;
}

public function where($column, $operator = null, $value = null, $boolean = 'and')
{
if ($column instanceof Closure && is_null($operator)) {
$column($this);
} else {
// TODO: Pass params to provider
dump(["where", $column, $operator, $value, $boolean]);
}
return $this;
}

public function get($columns = ['*'])
{
// TODO: Pass params to provider
return collect($this->items);
}

public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
return new LengthAwarePaginator($this->items, sizeof($this->items), $perPage);
}

public function getModel()
{
return new StaticModel;
}

public function __clone() {}
}
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
No description
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
class UserResource extends Resource
{
protected static ?string $model = "User";

public static function getEloquentQuery(): Builder
{
return new StaticBuilder([
new StaticModel([
"id" => "1",
"name" => "John Smith",
"email" => "[email protected]",
]),
new StaticModel([
"id" => "2",
"name" => "Jane Smith",
"email" => "[email protected]",
]),
]);
}

// ...
}
class UserResource extends Resource
{
protected static ?string $model = "User";

public static function getEloquentQuery(): Builder
{
return new StaticBuilder([
new StaticModel([
"id" => "1",
"name" => "John Smith",
"email" => "[email protected]",
]),
new StaticModel([
"id" => "2",
"name" => "Jane Smith",
"email" => "[email protected]",
]),
]);
}

// ...
}
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Wondering if it'd make more sense to try and create some sort of "mock Builder" and swap it in
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Likely Table class, Resource class, and a few traits rewritten also... Seems like a lot of work
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Regarding the filters issue, I came across this: https://github.com/filamentphp/filament/discussions/1088 If the filters can be serialized into a querystring, then they can likely be passed as an argument to a user-provided function to return filtered results
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
fair
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Of course, whatever makes sense for Filament. Either way, I'm willing to contribute with whatever's needed
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
I've searched for a few different things, but haven't found anything yet. Not really sure what to search for as I'm guessing different people will describe it in very different ways depending on their own specific use they'd have for it
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
I've just went through all 16 pages of Feature discussions, and came across this one: https://github.com/filamentphp/filament/discussions/6657
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
I'd be glad to hack away at the Filament source and try to implement something like this, however I'm not sure how well a PR/feature-discussion like this would be received as it doesn't seem like something that aligns much with the current Filament roadmap. Do you think it's worth me opening a feature discussion in https://github.com/filamentphp/filament/discussions ?
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
At least besides implementing my own Eloquent driver, which seems a tad overkill 😅
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
I say "for now", even though this would still require changes to the Filament source 😂 So far I can't think of any way of making this work purely on the user end
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
At least for now that'd be a solution
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
What would be great is an alternative method in which I could provide it with a simple collection of objects, even if filtering weren't possible for Resources not based on Eloquent
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
And I understand the need for it to be. Filament internally uses that Builder a lot
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Yep
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Even if that's possible, the main issue is getting data into Filament without it having to come from Eloquent
56 replies
FFilament
Created by tobyselway on 9/11/2023 in #❓┊help
Custom data providers
Agreed. Would there feasibly be a way of summarizing a list of applied filters in order to request them from a user?
56 replies