Search code examples
laravellaravel-5laravel-5.4laravel-5.5whmcs

How to solve the below mentioned error while performing login action in laravel


Find below the controller code:

class SigninController extends Controller
{
  protected function signin(){
    $login = Whmcs::validatelogin(array(
        'email' => Input::get('email'),
         'password2' => Input::get('password2'),
    ));

    if($login->result == 'success') {
        echo 'User Logged In';
    } elseif($login->result == 'error') {
        echo $login->message;
    }
  }
}

The route code is shown below:

Route::post('signin','SigninController@signin')->name('login.signin');

The form action in the blade file is given below:

 <form class="bs-example form-horizontal" action="{{route('login.signin')}}" method="post">
      <input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">

        <div class="form-group">
          <label class="col-lg-2 control-label">Email</label>
          <div class="col-lg-6">
            <input type="email" class="form-control" name="email" placeholder="Email">
          </div>
        </div>

        <div class="form-group">
          <label class="col-lg-2 control-label">password</label>
          <div class="col-lg-6">
            <input type="password" class="form-control" name="password2" placeholder="password">
          </div>
        </div>
        <div class="form-group">
          <div class="col-lg-offset-2 col-lg-10">
            <button type="submit" class="btn btn-sm btn-success">Submit</button>
          </div>
        </div>

      </form>

While executing the above code I'm getting an error as

Trying to get property 'result' of non-object. Suggest me solution to solve this while performing login action.


Solution

  • Try echoing the variable $login using

    dd($login);
    

    Most probably the output of validatelogin function is not an object.