Support the ongoing development of Laravel.io →
posted 9 years ago
Forms
Last updated 1 year ago.
0

He's wrong. Robbo is the least constructive member of the entire Laravel "community" and I recommend you do not take a single word of his to heart :)

Last updated 1 year ago.
0

Robbo isn't wrong. Your views shouldn't have to know about an entire model object. It should just have to know it has a simple object with simple attributes. The ORM spoils you so you ignore these things. Using Form at all is a code smell. Write the damn html by hand or use snippets. Don't change one syntax for another just because you like writing PHP (lol why?) more.

Last updated 1 year ago.
0

If we use eloquent model + Form::model, then it is a code smell because your view is tightly coupled to your model. The data that you want to display in a view (view specific data) might not be in your model. In that case, you either end up adding a new method in the model or call multiple methods from the model to construct the view specific data you want.

In either case, it is not best practice. The first approach is not good because you're adding a view specific method in your model (business object). The second approach is not good because you're violating DRY principle and increasing chance of making a mistake (you probably use the same view specific data in other views).

However, I think it is acceptable if we use a presenter + Form::model (assuming Form::model is smart enough to work with a presenter..or is it the other way around?). Some people might not agree that using a static class in a view is still bad, but I think it's acceptable in this case.

Last updated 1 year ago.
0

Form::model works with everything - StdClass, array, model, presenter... It's merely a way to not have to write the following sort of logic for every single field you want represented in your form:

$data['field'] = Session::has('_old_input.field') ? Session::get('_old_input.field') : (isset($model->field) ? $model->field : 'default');
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

hughgrigg hughgrigg Joined 19 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.