0
\$\begingroup\$

I have sample controller InboxController in my Inbox app. I want control with field name from my controller. If I will control with fields name from controller will not be destroyed MVC rules?

<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class InboxController extends Controller
{
 /*
 |--------------------------------------------------------------------------
 | Field names in HTML form
 |--------------------------------------------------------------------------
 */
 /**
 * Recipient field name.
 *
 * @var string
 */
 public $recipient = 'recipient';
 /**
 * Sender field name.
 *
 * @var string
 */
 public $sender = 'sender';
 /**
 * Subject field name.
 *
 * @var string
 */
}

Html code:

<input type='text' name="{{ $sender }}">
asked Jan 9, 2018 at 6:17
\$\endgroup\$
2
  • \$\begingroup\$ what are we supposed to be reviewing here? the two controller properties? yes, those are very nice. i have no suggestions. if you want to do something with them and you're not sure how, you should try asking on stackoverflow. \$\endgroup\$ Commented Jan 9, 2018 at 17:15
  • \$\begingroup\$ I just wanted to ask if it would be bad if the field names on the HTML form will be defined on the controller @I wrestled a bear once. \$\endgroup\$ Commented Jan 10, 2018 at 2:52

1 Answer 1

2
\$\begingroup\$

I recomend you to use Symfony like form builder. There you can create one form and reuse it anywhere.

$form = FormFactory::create(FormType::class, $user)
 ->add('name', TextType::class)
 ->add('email', EmailType::class, [
 'rules' => 'unique:users,email',
 ])
 ->add('save', SubmitType::class, ['label' => 'Save user']);

What is also good is with this form you can also validate your input at the same time.

 $form->handleRequest();
 if ($form->isSubmitted() && $form->isValid()) {
 //Your code
 }

Here is link for repository

answered Jan 10, 2018 at 7:49
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.