ffffer.
FileUpload for Cloudflare Images
In the end I made my own driver. But I have only one problem left that I can't solve:
class CloudflareImagesAdapter implements FilesystemAdapter
{
protected $client;
protected $apiKey;
protected $accountId;
protected $baseURL;
protected $response;
public function __construct(string $apiKey, string $accountId, string $baseURL)
{
$this->client = new Client([
'base_uri' => 'https://api.cloudflare.com/client/v4/accounts/' . $accountId . '/images/v1',
]);
$this->apiKey = $apiKey;
$this->accountId = $accountId;
$this->baseURL = $baseURL;
}
public function write(string $path, string $contents, Config $config): void
{
$response = $this->client->post('', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiKey,
],
'multipart' => [
[
'name' => 'file',
'contents' => $contents,
'filename' => basename($path),
],
],
]);
if ($response->getStatusCode() !== 200) {
throw new \Exception('Failed to upload file to Cloudflare Images');
}
}
The problem is that after the upload, I get:
{
"result": {
"id": "2cdc28f0-017a-49c4-9ed7-87056c83901",
"filename": "image.jpeg",
etc...
}
Filament is storing in my model Image: "image.jpeg", but I need to store: "2cdc28f0-017a-49c4-9ed7-87056c83901"
How could I do that?
Thanks8 replies
FileUpload for Cloudflare Images
Thanks for the replies.
With R2 everything works perfect for me because it uses it as a native disk. The problem is that CF Images is not R2, the way to save and view images is directly HTTPS (save with a post/curl, and load with the direct url).
https://developers.cloudflare.com/images/upload-images/upload-url/
8 replies
FileUpload for Cloudflare Images
Ok, I understand.
I'm trying to use the FileUpload to manage Cloudflare Images (it works with http calls)
I'm using saveUploadedFileUsing to upload files, it works. But my problem is that I cannot view the uploaded file. Any recommendation?
The ideal solution should be a filesystem disk, but I didn't find any working pkg for that.
8 replies
Back to default within method
I understand, but wouldn't it be more convenient that if null is returned for example, it adopts the default behavior?
Or that there is some method to avoid these cases in which if there is no real change in behavior, because if I implement the current logic and in a later version the base function is changed, it may not work as expected
Thanks for the clarification
5 replies
RelationManager select relationship with multiple(), Duplicate entry on update
Thanks for the reply, but the withPivot() method is not necessary if the pivot table doesn't have any additional columns besides the foreign keys:
In Laravel, when you define a many-to-many relationship using belongsToMany(), Laravel will automatically handle the foreign keys in the pivot table.Any other idea?
10 replies
RelationManager select relationship with multiple(), Duplicate entry on update
Hi, sure:
class Domain extends Model:
public function assets_contents()
{
return $this->belongsToMany(AssetsContent::class);
}
class AssetsContent extends Model:
public function image()
{
return $this->belongsTo(Image::class);
}
And the pivot migration:
Schema::create('assets_content_domain', function (Blueprint $table) {
$table->unsignedInteger('assets_content_id');
$table->foreign('assets_content_id')->references('id')->on('assets_contents');
$table->unsignedTinyInteger('domain_id');
$table->foreign('domain_id')->references('id')->on('domains');
$table->primary('assets_content_id','domain_id');
});
10 replies
KeyValue field breaks json into array of characters
I have:
class ActionInbound extends MorphPivot
{
protected $table = 'action_inbound';
public $incrementing = false;
public $timestamps = false;
protected $casts = [
'inbound_id' => 'int',
'action_id' => 'int',
'config' => 'array',
'actionable_id' => 'int'
];
Note: if I remove that 'config' cast, and try to create a new attach, I got error: "Array to string conversion", so the cast is taken into account.
In class Action, I have:
public function inbounds()
{
return $this->belongsToMany(Inbound::class)
->using(ActionInbound::class)
->withPivot('config', 'actionable_type', 'actionable_id', 'choice');
}
As far as I know, I don't have any other casts for such 'config' var.14 replies
KeyValue field breaks json into array of characters
In other models that are not a MorphPivot, is working well, even with json casting (array or json works well both). For example I have some relation managers with a relationship with another model and there is no problem, it's shown and saved properly.
I tried with:
class ActionInbound extends Pivot
But there is no change in the behaviour, I have no tried with a different pivot14 replies
KeyValue field breaks json into array of characters
It should, but it's not an array, at least it has been printed every character in a row. When I do the json_decode (it's only a test, I don't want to do the json_decode as I think it shouldn't be necessary), then it's printed well but then I can't save it (error ($state) must be of type ?array, stdClass given)
I tested that the pivot it's been loaded, and it is. I don't know why this behaviour
14 replies
KeyValue field breaks json into array of characters
Hi, I'm having the same problem, but casting as array does not work, it's still showing wrong.
I'm using it in a pivot with:
class ActionInbound extends MorphPivot
{
protected $table = 'action_inbound';
public $incrementing = false;
public $timestamps = false;
protected $casts = [
'inbound_id' => 'int',
'action_id' => 'int',
'config' => 'array',
'actionable_id' => 'int'
];
Using:
->formatStateUsing(function($state) {
return json_decode($state);
})
Shows it properly, but generates the error:
Filament\Forms\Components\KeyValue::Filament\Forms\Components\{closure}(): Argument #1 ($state) must be of type ?array, stdClass given, called in vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
So I think is not the best solution.
Any workaround? Thanks14 replies
Builder schema not being reactive
Hi @awcodes ,
Thanks for the clarification, I'm using data objects for each 'type', so in the Builder, depending on the selected type, I need some fields to be filled in or others. Actually, my blocks looks like:
\Components\Builder\Block::make('data')
->label('Features')
->hidden()
->schema(function (callable $get) {
$type = $get('type');
$className = $type ? ucfirst($type) . 'BonusData' : null;
$classPath = "\App\Data\{$className}Data";
return class_exists($classPath) ? self::getReflection($classPath) : [];
})
->reactive()
->columns(3)
This way, as the 'type' select automatically takes the options from the db, simply by adding a new spatie data object we could extend the different fields for each option
5 replies