1

I am getting the following error code

Creating default object from empty value

When I dump the $post it returns null, however when I dump $id it returns the ID.

The controller code is as follows:

public function update(Request $request, $id)
    {
       $this->validate($request, array (
            'post' => '',
            'mailbox' => '',
            'conum' => '',
            'prefix' => '',
            'telans' => '',
            'TC' => 'required',

        ));

        //store
        $post = Customers::find($id);

        dd($id);

        $post->post = $request->input('post');
        $post->postpro = $request->input('mailbox');
        $post->telans = $request->input('telans');
        $post->conum = $request->input('conum');
        $post->prefix = $request->inut('prefix');
        $post->tc = $request->input('TC');

        //save
        $post->save();

        //session flash message
        //Session::flash('success','This customer has now been added');

        //redirect
return redirect('/home');} 

The form in the index file is as follows

{!! Form::model('Customers', ['route'=>['products.update', Auth::user()->id],'method' => 'PUT']) !!}

 {{ Form::hidden('business', Auth::user()->name, array('class' => 'form-control', 'required' => '','maxlength'=>'255'))}}


    {{ Form::label('post', 'Mailbox')}}
    {{ Form::checkbox('post',1, 0, array('class' => 'form-control'))}}
        <div id="extra_form">
        {{ Form::label('mailbox', 'Mailbox Option')}}</br>
        {{ Form::select('mailbox', array('rolling' => 'Rolling','month' => 'Monthly','year' => 'Yearly'), 'null', array('class' => 'form-control'))}}
        </div>
    {{ Form::label('conum', 'Company Number')}}
    {{ Form::checkbox('conum',1, 0, array('class' => 'form-control'))}}
        <div id="extra_form1">   
        {{ Form::label('prefix', 'Preferred number prefix')}}
        {{ Form::tel('prefix', 0, array('class' => 'form-control'))}}
        </div>
    {{ Form::label('telans', 'Telephone Answering')}}
    {{ Form::checkbox('telans',1, 0, array('class' => 'form-control'))}}
        <hr>
        <div id="extra_form3">
            {{ Form::label('posttc', 'Mailbox Terms and Conditions')}}</br>
            Click here
        </div>
        <div id="extra_form2">
            {{ Form::label('conumtc', 'Company Number Terms and Conditions')}}</br>
            Click here
        </div>
        <div id="extra_form4">
            {{ Form::label('telanstc', 'Telephone Answering Terms and Conditions')}}</br>
            Click here
        </div>-->
    {{ Form::label('TC', 'I accept the Office Flex terms and conditions.')}}
    {{ Form::checkbox('TC',1, 0, array('class' => 'form-control','required'=>''))}}
    {{ Form::submit('Select Product', array('class' => 'btn btn-success', 'id' => 'create_btn'))}}
{!! Form::close() !!}
3
  • 1
    Are u sure u've customers with id you're passing? Commented May 22, 2016 at 21:13
  • Thats the reason, thank you! Was Auth id was coming from the users table! Cant believe I didnt see that. Commented May 22, 2016 at 21:20
  • check your Auth::user() . . dd it.. may be its the issue. your Auth::user may be null and as its trying to get ->id from it error throws saying that you are trying to get property from null. Commented May 22, 2016 at 21:20

1 Answer 1

0

I added the following code to make sure the correct table ID was being added.

 $id = DB::table('customers')->where('business', Auth::user()->name)->pluck('id');
    $iid=implode($id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.