louisse
louisse

Reputation: 19

laravel controller problems wih if-statement

in controller

  if ($userLike) {
     $comment->likeIt();
     return response()->json(['status' => 'success','message'=>'liked']);
  } else {
     $comment->unlikeIt($$userLike->id);
     return response()->json(['status' => 'success','message'=>'unliked']);
 }

i want to have if(!$userLike) but i have one error in console POST http://learn.com/comment/like 500 (Internal Server Error)

Upvotes: 1

Views: 35

Answers (1)

Ali
Ali

Reputation: 2688

If you posted data using javascript (ajax or jquery), you should post data with CSRF-TOKEN. This link will help you : https://laravel.com/docs/master/csrf#csrf-x-csrf-token

You should add this line,

'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

Upvotes: 1

Related Questions