gearbox-solutions / eloquent-filemaker

A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
https://gearboxgo.com
MIT License
57 stars 16 forks source link

How to upload a file and update portal data fields #13

Closed mudassirali007 closed 2 years ago

mudassirali007 commented 2 years ago

I am facing two issue, like your help

  1. I am using this syntax in laravel 8 and filemaker 19 to upload file

    $product = Layout::findByRecordId($id);
    $product->Image = new File(storage_path('test.png'));
    $product->save();

    and getting this error image

  2. updating a portal data value which is an array $product->InventoryTransactions[0]['InventoryTransactions::Units'] = 3; and getting this error image

PS: portal data is an array format

Smef commented 2 years ago

It looks like you're using the raw internal FileMaker record ID instead of regular model queries. You don't get a model back when you use the raw queries like that, so I don't think save() is going to work since there is no model to save. I would recommend using models for your data instead of raw queries. Can you give that a try? I think you'll have much more success that way.

mudassirali007 commented 2 years ago

so what about file upload?

Smef commented 2 years ago

I'm not sure what your Layout class is there. It's not from this package, so I'm guessing this is something you've made custom. I don't know what it is returning or what you're doing with it, and so I can't provide any help with that. You're also using the findRecordByID and the internal FileMaker IDs, so you're not using eloquent models with your primary keys and are instead using the raw query builder and getting raw data back, again, not in the way you should probably be doing it which was the same issue in your last post.

If you're using the raw query builder you use the saveContainer method to write a container field, but again, I don't recommend using the raw query builder unless you can't use a model for some reason.

If you're using a model class it's easy to set a file and then call the save method, but looks like you have your own implementation of save() there, so I don't know what you're doing in that method.

If you're querying and getting a model to retrieve the internal, hidden FileMaker ID you shouldn't need to use the findByRecordID method since you already have a model object, so again, I don't think you're approaching this the right way and shouldn't be building your own methods for all of this behavior.

I would do this like this:

(assuming you have a model named Product and a container field named image)

  1. Find a product using your primary key to get a model object
  2. Update the container field
  3. Save the model object, which will write the container to your database.
 $product = Product::find($id);
 $product->image = new File(storage_path('test.png'));
 $product->save();