2

When I run the code given below I am getting the following error

error: {type: "ErrorException", message: "Creating default object from empty value"}

at this $mandate->user_id = $current_user; line. I have tried this and this but still shows the same error. Thanks for any suggestions.

public function postProcess()
{
    $id = Input::get('id');
    $button_id = Input::get('button_id');
    $remarks = Input::get('remarks');
    $current_user = Sentry::getUser()->id;
    $mandate = new Mandate();
    $mandate = Mandate::find($id);

    $mandate->user_id = $current_user;
    $mandate->remarks = $remarks;

    $eventlog = new Eventlog();
    $eventlog->user_id = $current_user;
    $eventlog->mandate_id = $id;

    if($button_id == "reject"){
      $rejectreason_id = Input::get('rejectreason_id');
      $rejectreason = Input::get('rejectreason');
      $mandate->mandate_status = "Rejected";
      $mandate->rejectreason_id = $rejectreason_id;
      $eventlog->event = "Rejected: ".$rejectreason;   
    }else if($button_id == "verify") {
      $mandate->mandate_status = "Awaiting approval";
      $eventlog->event = "Verified";
    }
    else if($button_id == "approve") {
      $mandate->mandate_status = "Approved";
      $eventlog->event = "Approved";
    }

    $eventlog->save();
    $mandate->save();
    $this->generateXML($id,$rejectreason);
}

EDIT 1 (As suggested by Suresh Kamrushi)

public function postProcess()
{
    $id = Input::get('id');
    $button_id = Input::get('button_id');
    $remarks = Input::get('remarks');
    $current_user = Sentry::getUser()->id;
    $rejectreason = "";
    $mandate = new Mandate();
    $mandate = Mandate::where('id',$id)->first();

    if(is_object($mandate)) {
      file_put_contents('log.txt', print_r("no mandate", true));
      $mandate->user_id = $current_user;
      $mandate->remarks = $remarks;
      $eventlog = new Eventlog();
      $eventlog->user_id = $current_user;
      $eventlog->mandate_id = $id;

      if($button_id == "reject"){
        $rejectreason_id = Input::get('rejectreason_id');
        $rejectreason = Input::get('rejectreason');
        $mandate->mandate_status = "Rejected";
        $mandate->rejectreason_id = $rejectreason_id;
        $eventlog->event = "Rejected: ".$rejectreason;
        //$this->generateXML($id,$rejectreason);   
      }else if($button_id == "verify") {
        $mandate->mandate_status = "Awaiting approval";
        $eventlog->event = "Verified";
      }
      else if($button_id == "approve") {
        $mandate->mandate_status = "Approved";
        $eventlog->event = "Approved";
        //$this->generateXML($id,$rejectreason);
      }

      $eventlog->save();
      $mandate->save();
    }
}

Now the error is gone but the code inside if statement is not working now.

0

1 Answer 1

1

Try something like this:

$mandate = Mandate::find($id);
if(is_object($mandate)) {
  $mandate->user_id = $current_user;
  $mandate->remarks = $remarks;
}
Sign up to request clarification or add additional context in comments.

2 Comments

The error is gone but the code inside 'if' statement not working. as given in EDIT1
@NithilGeorge: You have problem with "Mandate::find($id);" check Mandate class with find() is available or not. because of that $mandate is not initiating and it is not going inside if condition.

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.