Your code returns a Collection
with a single Model
(or multiple models if there are more matching the where clause), while the method you need is pluck
:
return Fanpages::where('url', '=', $pageName)->pluck('id');
// returns INT 17
as it returns value for column id
of the first row matching WHERE
clause.