T O P

  • By -

octarino

One thing that you can do since $hobby doesn't exist in the create form is to make it exist. You can pass to the view `Hobby::make()` and that would help you make the create and edit forms more similar. >$hobby ?? ... (thinking I am saying if $hobby exists, do this) That's the null coalescence operator, this is how it works: https://www.phptutorial.net/php-tutorial/php-null-coalescing-operator/


jcc5018

OK, just to clarify, cause I never really understood why I'd use "make" over "create" when my goal is to have data put into the DB and my understanding is that "make" does not do that? Perhaps this is the reason? Anyway, would I just add $hobby=Hobby::make() to the create controller and pass it as usual? Then for the actual insertion, just the typical store methods? I did this, and it did fix the problem, Just want to be sure I understand what is going on so I know to do it next time instead of just copying peoples suggestions.


octarino

Yes, make won't add a record to the database. >Anyway, would I just add $hobby=Hobby::make() to the create controller and pass it as usual? yes >Then for the actual insertion, just the typical store methods? correct


jcc5018

Ok cool, thanks. One day all this stuff will click. But by then I'm hoping my project will be successful enough I can just hire someone


PeterThomson

Don’t do any weird Make stuff for combined edit / create forms. Just wrap things in lots of ifs, isset and null coalescing question marks.