I'm experiencing some weird behaviour.
I'm selecting a single record from my database using: Model::find(id).
Since I have to distinguish if I have a single record or multiple I need to count my records.
I'd like to use Builder::count() for this. I call it inside my template as followed: $model->count().
However, here's the part where I ... well ... get crazy.
If I use Model::find(id)->count()or Model::where(condition)->first()->count() I always end up getting 2 as result. On the other hand, if I use count($model) or Model::where(condition)->get()->count() I end up getting the correct result (1), which is what I need.
Basically when you do a count on the model instance it returns all the results not always 2 as your example, that might be because in your database for the model you have only two rows, but having 50 it will return 50. The proper way is to use the where clause, then you can do just
@BroJenuel it depends. This is pretty much like running an SQL statement, so it should be fast, but depends on your where clause. If you are adding multiple checks, your field is not indexed or anything, might be slow. So you should test that.
@NEEONLINE - of course not! For go'd sake... primary keys are unique.
It's just that I tried to be lazy and wanted to reuse the same template multiple times. I do have multiple records but everytime with a different primary key (1,2,3,4, etc.).
Depending on the situation I'd like to retrieve my records with Model::find($id) or Model::where(condition).
@NAKOV - I'm totally sorry if I didn't write my question as it's been intended to be asked. I've tried various things already but always end up with > 1 "record" when I'm using $model->count(). To be precise: I get exactly the records as intended (1 or n), but $model->count()returns on a single record 2 (using find() or first()) or the intended amount of records, when using get() or count($model).
As descript in my answer to neeonline, I've tried to distinguish between different cases while reusing templates.