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: …
Tag: eloquent
Return values only (no keys/associative array) in Laravel
Situation I have the following code to get all data as an array: This will return the data in the following format: But I want only the values as a regular array (no keys/associative array) so the array is not converted to an object when I convert it to JSON: Inadequate solutions I know I can convert this with a
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
Laravel 5.1 – BelongsTo relationship returns null
AppUser class User public function status() { return $this->belongsTo(‘AppUserStatus’, ‘user_status_id’, ‘id’); } AppUserStatus class UserStatus protected $fillable = [‘id’]; public …
Sorting Children in Laravel : How do I sort children by name?
Below is my controller code When I access my categories and its children in the view, the categories seem to be sorted by name but the children categories are not. How do I sort the children categories as well by name? Also, is it possible to sort the categories using a different criteria than the children eg. By position for
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
Laravel findOrFail with related data?
In my Menu controller I have a method which should display the specified record and all its children. I have two models: MenuItem and MenuVariation, My items will have many variations as outlined in …
Laravel – Where to store statuses (flags)? Model, Class or config folder?
I need to extensively use statuses in mt project. I need them for my users (active, suspended, etc), an entity (active, pending_activation, inactive) and for my subscriptions(active, on_grace_period, not_subscribed, never_subscribed). So far I thought that the best way is to store them in the DB but i have a feeling it’s much easier to have them in the other 3
Eloquent chunk() missing half the results
I have a problem with Laravel’s ORM Eloquent chunk() method. It misses some results. Here is a test query : $destinataires = Destinataire::where(‘statut’, ‘where(‘tokenized_at’, ‘&…