0

im doing save cookie but have a problem . Here is my helper

public function check_if_exist($user){

    $isExisted = User::where('email', $request->get('email'))->first();

    if(!$isExisted) {
        $user = new User();
        $user = $user->isExisted($request);
        $user->save();
        Cookie::queue($user);
    }
    Cookie::queue($user);
}

and here is my controller , i

public function store(SignRequest $request, WiuCookie $wcookie, CheckUser $check)
{
    $check = ActionUsers::where('petition_id', $request->get('petition_id'))->where('email', $request->get('email'))->first();

    if($check) {
        return back()->with('fail','You fail');
    }

    $sign = new ActionUsers();
    $sign = $sign->init($request);

    if( $sign->save() ){

        $wcookie->setById($sign->petition_id);
        $check->check_if_exist($sign);
        return redirect('/thanks/signed/'.$sign->petition->slug);

    }else{
        return redirect()->back();
    }
}

and error is

Call to a member function check_if_exist() on null.

I dont know i called variable right or not. i'm use enough params but it's not working Anyone can solve that. Thanks

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
Nguyễn Minh Huy
  • 265
  • 4
  • 6
  • 15
  • When you do `$sign->save()` check if it properly persist to the db. The issue seems to be that `$sign` is `null'. – Gayan Sep 15 '17 at 04:37
  • Duplicate of a million SO questions. Have tried searching the Internet? – marekful Sep 15 '17 at 04:37
  • Where did you define the check_if_exist() function? – Fil Sep 15 '17 at 04:52
  • In the controller, if $check stands for true then it has to redirect back.and if it is not an object, it is null that's why you are getting this error. – Alankar More Sep 15 '17 at 05:30
  • Check this statement " ActionUsers:: where" really returns you object of ActionUsers and I think you have to modify if condition as if(!$check) – Alankar More Sep 15 '17 at 05:31

2 Answers2

0

CheckUser $check you are passing in the function store(). Where is CheckUser. If it is in some class, have you given namespace in controller.

Mahi
  • 105
  • 8
0
$check = ActionUsers::where('petition_id', $request->get('petition_id'))->where('email', $request->get('email'))->first();

this line is probably giving you a null value.

Jerico Pulvera
  • 1,032
  • 7
  • 15