BrianDillingham
3 years ago

Clean way to inject old input

Posted 3 years ago by BrianDillingham

This, to me atleast, feels like a clean way to have edit & create views share fields

Shared Input

<input type="text" name="first_name" value="{{ old('first_name', $contact->first_name) }}">

Create & Edit Method - Because $contact isn't defined in create it throws an exception.

Any opinions / thoughts on adding an empty model, making the default value of old() = empty.

public function create()
{
        return view('contact.create')->withContact(new Contact);
}

public function edit($id)
{
        $contact = Contact::find($id);

        return view('contact.edit', compact('contact'));
}

Please sign in or create an account to participate in this conversation.