update error - Creating default object from empty value

Posted 1 year ago by johnnw

I have a view to editing registration types but when the store button is clicked it appears:

"Creating default object from empty value".

If I change "$regType = RegistrationType::find($conference->id);" to " $regType = RegistrationType::where('conference_id', $id)->get();" appears the error:

"Method save does not exist."

Do you know where is the issue?

The user accesses "http://proj.test/conference/edit/3/rtypes" to edit the registration types. Here there is a form:

<form method="post" class="clearfix">
    <div class="form-row">
        <div class="form-group col col-lg-6">
            <label for="registration_types">Registration Types</label>

            @foreach($registrationType as $rtype)
                <div class="form-check">
                    <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
                    <label class="form-check-label" for="exampleRadios1">

    <div class="form-group">
        <label for="registration_type_name" class="text-heading h6 font-weight-semi-bold">Registration Type Name</label>
        <input type="text" required class="form-control" value="{{ $rtype->name }}" name="registration_type_name" id="registration_type_name">
    <div class="form-group">
        <label for="registration_type_capacity" class="text-heading h6 font-weight-semi-bold">Capacity</label>
        <input type="number" min="1"
               required class="form-control" value="{{ $rtype->capacity }}"
               name="registration_type_price" id="registration_type_capacity">
    <!-- more registration type info fields -->
    <input type="submit" class="btn btn-primary" value="Store registration type"/>

// RegistrationType controller edit method:

public function edit($id)
        $conference = Conference::find($id);
        $registrationType = RegistrationType::where('conference_id', $id)->get();

        return view('rtypes.edit')->with('conference', $conference)->with('registrationType', $registrationType);

// RegistrationType controller update method:

public function update(Request $request, $id){

        $this->validate($request, [
            'registration_type_name' => 'required|string',
            'registration_type_description' => '',

        $conference =Conference::find($id);
        $regType = RegistrationType::find($conference->id);

        $regType->name = $request->registration_type_name;
        $regType->description = $request->registration_type_description;


        return redirect()->back();

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

Reply to

Use Markdown with GitHub-flavored code blocks.