Skip to content
Advertisement

Tag: eloquent

Laravel Distinct Count

Any way to make this query work using laravel? DB::raw or Eloquent usage doesn’t matter. SELECT count(DISTINCT name) FROM tablename; Here’s what i’ve tried but cannot get the proper output: …

Laravel: find if a pivot table record exists

I have two models which are joined by a pivot table, User and Task. I have a user_id and a task_id. What is the neatest way to check whether a record exists for this combination of user and task? Answer You have a couple options depending on your situation. If you already have a User instance and you want to

Difference between EloquentModel::get() and all()

What is the difference between uses User::all() and User::get() on Eloquent? On Laravel API it describes only all() on EloquentModel.Maybe get() is described on EloquentBuilder. Answer User::all() and User::get() will do the exact same thing. all() is a static method on the EloquentModel. All it does is create a new query object and call get() on it. With all(), you

How do I get a list of all models in Laravel?

I would like to find a list of all models, database tables as a backup, in a Laravel project. I want to do this to build a dashboard that displays the way data in all of the models has changed over time, I.E. if there is a user model, how many users have been added or modified each day for

Advertisement