php (if) condition is not working in laravel

There is the problime:

if(DB::select("select count(*) from likesrate where user_id='$user_id' and book_id='$book_id'")==0)

The query does not return an integer to compare it with 0.

What you can do is something like:

$likes_count = DB::table("likesrate")->where("user_id", $user_id)->where("book_id", $book_id)->count();

if($likes_count == 0){
    // blah blah blah