I'm new to Laravel and i need your help please.

This runs on my controller and the result should be "3" as long as I have 3 rows with that title in the same table.

```
 $countcategories = DB::table('categories')
                ->select(DB::raw('count(title) as result'))
                ->where('title','=','dsds')
                ->get();

```

I'm passing the query result to the view like this`->with('counts', $countcategories)`

And now my questions are:

1. In the view I can only display the result by using `foreach`. Why? My query returns only one row.
2. I want to store the query result in a variable inside my controller in order to use that result. How can I do that?

Thank you very much!