Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Best way to edit table when using blade

I've figured out what part in the code makes the page load 75MB: the developer before used Laravel blade as frontend and he loads the data into table. Now the data alone is only 2MB.

But what he did, because he wanted the ability to edit every cell (and then update accordingly in the db) was to open a form before the table using Form::open, and inside each cell he outputs the data inside input tags. So I think that's what makes it so bloated: it's a gigantic form with hundreds of inputs that the user can edit, and then when you save, it just send everything to the backend, hundreds of inputs.

What would be a better way to be able to update individual cells? I was thinking about JS + AJAX, but maybe there's a way to do it purely with blade?

Also, where did the Form::open come from? The project uses Laravel 6 and I only found it in the docs of Laravel 4.. So is it another mistake?

One more thing: I'm still not sure what exactly makes the 2MB into 75MB: Is it the fact that many input tags are used, the usage of Form::open, or something else?

0 likes
7 replies
Tray2's avatar

Without any example code it's hard to understand and help you.

The Form::open is from something called the FormHelper, it was removed from Laravel many years back, it has however sadly lived on in the Laravel Collective. It should not be used.

1 like
Ligonsker's avatar

@Tray2 thank you, will probably have to redo the entire thing. Assuming I do it from scratch: I fetch all the rows from the db and display as a nice table. But then, what should i use in order to be able to edit individual cells? Would you use some JavaScript + AJAX calls? OR there's a way to do it with HTML and blade alone? though not sure.

One more thing, I noticed they use Eloquent to fetch data, and then the DB rows are full of objects which I think uses more data? (Currently 3MB), So maybe there is a way to just get the data as JSON or other source of data which is less "heavy"? I remember I saw a method that "flattens" the objects but can't remember which

Sinnbeck's avatar

@Ligonsker about this

I fetch all the rows from the db

Unless you have like a maximum of a 100 rows, you should not do this. Use pagination. My guess is that the previous programmer didn't use pagination, and that will use alot of memory

1 like
Ligonsker's avatar

@Sinnbeck there is pagination but I think he didn't implement it correctly, I'm gonna have to check it next week I think he did something really wrong there

Ligonsker's avatar

@Tray2 will do! however I think without livewire but using fetch API or jQuery ajax

Snapey's avatar

Open a modal window with the selected row allow edit and send it to the server. You could do it with ajax, but if its just a table it wouldn't be so bad to just reload the page after the update.

Or, what I would do is use Livewire.

1 like

Please or to participate in this conversation.