You should remove the single quotes around the expression otherwise it will be treated as a string.
$firstCategory = '$category[0]->cat_name';
Should be changed to:
$firstCategory = $category[0]->cat_name;
Then you can try basic debugging like printing the output of the $category
and $category[0]->cat_name
.