Laravel - Saving PDF into a BLOB, causing job serialization issues - laravel

I am storing a raw PDF into a binary/blob column in my database. This all works great in most cases.
I had an issue a while back with livewire where the blob was causing issues with rendering. This was easy to fix by adding the blob column to the models hidden array:
https://laravel.com/docs/8.x/eloquent-serialization#hiding-attributes-from-json
I am now back here with a similar issue but no fix. When pushing one of these models into a job, the serializer fails due to not being able to encode this column.
The error we get is:
Unable to JSON encode payload. Error code: 5
My options/ideas so far:
base64 encode the PDF and save into a text field.
Maybe the new Laravel job encryption feature may help, but I am not on a version to be able to test this just yet.
Does anyone have any other ideas?

Remove the trait SerializesModels from your Job class or use an Eloquent model into constructor
From Laravel documentation
if your queued job accepts an Eloquent model in its constructor, only the identifier for the model will be serialized onto the queue. When the job is actually handled, the queue system will automatically re-retrieve the full model instance and its loaded relationships from the database. This approach to model serialization allows for much smaller job payloads to be sent to your queue driver.
Or dont use the whole model in the constructir but use the id directly.
Or simply save the PDF file to the filesystem and keep only its path in the database. Will ave you a lot of database read/write time + all the tinkering regarding big payloads

Related

Repeatable Data in Laravel

I'm creating a Laravel app but come from a WordPress background. In WordPress, it's reasonably straight forward to create custom fields that are repeatable e.g. I have a field called "Task" that can be repeated X number of times and it will be stored on the database.
Is there a best practice way of doing this in Laravel?
I understand that Javascript can be used to create repeatable form fields, and I could store that data as JSON in a MySQL database (using the latest versions of MySQL), but I'd also like this repeatable data to hold relationships e.g. relate a task to a day of the week (stored in another table).
Any advice or thoughts are much appreciated.

Laravel Queues Doc. - Passing an Eloquent Model

There is a statement I don't understand in Queues chapter of Laravel's 5.5 documentation. It says:
If your queued job accepts an Eloquent model in its constructor, only
the identifier for the model will be serialized onto the queue.
I want to understand what this means. Thanks in advance.
Well, you should read further:
When the job is actually handled, the queue system will automatically re-retrieve the full model instance from the database. It's all totally transparent to your application and prevents issues that can arise from serializing full Eloquent model instances.
what means that if you pass to Queue user with id 1 and something will be changed before executing job than when executing this job, those changes will be available because fresh model will be taken from database.

REST client that can consume any REST API run-time and persist the data creating new tables dynamically

I'm looking for a solution with Spring / camel to consume multiple REST services during runtime and create tables to store the data from REST API and compare the data dynamically. I don't know the schema for JSON API in advance to generate the JAVA client classes to create JPA persistent entity classes during run time.
You'll need to think through this differently. Id forget about Java class POJOs that you don't have and can't create since the class structure isn't known in advance. So anything with POJO->Entity binding would be pretty useless.
One solution is to simply parse the xml or json body manually with en event-based parser (like SAX for XML) and simply build an SQL create string as you go through the document. Your field and table names would correspond to the tags in the document. Without access to an XSD or other structure description, no meta data is available for field lengths or types. Make everything really long VARCHAR? Also perhaps an XML or other kind of database might suite your problem domain better. In any case, you could include such a thing right in your Camel route as a Processor that will process the body and create the necessary tables if they don't already exist. You could even alter a table for lengths in the process when you have a field value that is longer than what's currently defined.

Rhomobile inserting into local database using CSV or XML from external web server

I am currently developing a Rhomobile application. I have a backend database which holds customer information. I have got from the webserver a csv string (or XML - I am able to parse the XML using REXML) which contains all the customers. Each time I sync the device I am going to reset the customer table on the device and re-insert all data from the backend database. I am not using RhoSync and the device will be using property bag.
Is it possible to use the CSV or XML data to insert into the customers table? If so, how would I go about it?
At the moment the only option I can see that would work would be to manually loop through the CSV/XML and insert into the database manually; this isn't very elegant.
Any help will be much appreciated, sorry if this is a dumb question; still relatively new to this framework.
I have come to the conclusion that the only way is to loop through the csv/xml, which with the help of a database transaction this doesn't take long.
Using fixed schema also increases the performance a lot as property bag has to do column inserts (so if you have lots of columns - there is lots of inserts per record).
Also in Rhomobile garbage collection is turned off, so if you are trying to process large data sets your device will quickly run out of memory:
GC.enable
The above solves this issue

Can Core Data content be edited directly?

I've been using Core Data for about a week now, and really loving it, but one minor issue is that setting default values requires going through and setting up a temp interface to load the data, which I then do away with once I have the data seeded. Is there any way to edit values in a table, like how you can use phpMyAdmin to manipulate values in a MySQL database? Alternately, is there a way to write a function to import seed values from something like a Numbers spreadsheet if it doesn't detect the storedata XML file?
For your first question, you could edit the file directly but it's highly recommended you don't. How to edit it depends entirely on the store type you selected.
Regarding importing or setting up pre-generated data, of course: you can write code to manually insert entity instances into your Managed Object Context. There's a dedicated section on this very topic in the documentation. Further, if you have a lot of data to import, there's even a section on how to do this efficiently.
Is there any way to edit values in a
table, like how you can use phpMyAdmin
to manipulate values in a MySQL
database?
Xcode has a means of creating a quick and dirty interface for a data model. You just drag the data model file into a window in interface builder and it autogenerates an interface for you. This lets you view the data without having to have your entire app up and running.

Resources