Home >

laravel 5 eloquent get count

  • How do I get a "select count(*) group by" using laravel eloquentJanuary 16

    I would like to execute the follow sentence using laravel eloquent SELECT *, count(*) FROM reserves group by day The only solution occurs to me is to create a view in the DB, but I am pretty sure there is a way to do it in laravel way. --------------

  • Laravel Eloquent ORM - removing rows and all the child relationship, with event deletingJanuary 25

    I have three models that relate to each other one to many: Country class Country extends Model { protected $fillable=['name','sort']; public $timestamps=false; public function region(){ return $this->hasMany('App\Models\Region'); } } Region class Reg

  • Getting all related tables of a specific table in Laravel EloquentJanuary 27

    I have an application implemented in laravel in which I want to add record rules security feature. The story is that admin selects a resource(object type) in the system as well as some user roles(groups) and then specifies rules for actions on that r

  • Laravel - Eloquent where with relationship?January 27

    I have the following code: return Technology::WhereIn('uuid', $technologies)->get(); $technologies is an array of UUIDs and in my $technologies table I have a uuid field. So this will return the technologies that match up with the UUIDs, but I also h

  • laravel Eloquent one to many two relationship. OpenCart table style

    laravel Eloquent one to many two relationship. OpenCart table styleJanuary 29

    How to implement information and information_description tables in laravel Eloquent Model ? Some how it need to set language, because a title should be a one record. $information = App\Information::find(1); $information->title --------------Solutions

  • How to get the count of Left and right referral ids with laravel eloquent query

    How to get the count of Left and right referral ids with laravel eloquent queryFebruary 14

    Hello experts I am totally new with php and laravel. Can you suggest me with laravel 5.1 eloquent query how to get the total count of left referrals and right also. Thanks in advance public function downline_count($uids, $count) { $donwlines = Downli

  • Laravel Eloquent querying pivot table not uniqueJanuary 17

    For some reason I don't get the expected result when doing the following: $cars = Car::query(); $cars->whereIsVisible(true); # output: $list // [2016-01-16 09:30:04] local.INFO: array ( // 0 => 5, // 1 => 7, // 2 => 9, // 3 => 3, // ) $cars

  • Need to convert raw queries into laravel EloquentJanuary 21

    Below is my raw MySQL query: SELECT T1.id, T1.department_id, COALESCE(T2.cnt, 0) AS cnt FROM (SELECT DISTINCT id, department_id FROM users WHERE company_id = '33') AS T1 LEFT JOIN ( SELECT user_id, COUNT(*) AS cnt FROM userlogs WHERE created_at BETWE

  • Laravel Eloquent: How to get only certain columns from joined tablesFebruary 6

    I have got 2 joined tables in Eloquent namely themes and users. theme model: public function user() { return $this->belongs_to('User'); } user model: public function themes() { return $this->has_many('Theme'); } My Eloquent api call looks as below:

  • Extended Laravel Eloquent models to add filters to model settersOctober 10

    One of the tasks I find myself doing repeatedly is to filter the incoming inputs that will be stored in models. Examples of this include trimming, removing repeated or unnecessary pre/suffixes, commas or dashes in numbers, etc. This is similar to val

  • Laravel Eloquent, JOIN queryJanuary 14

    I need some help to do this query on Eloquent. select COUNT(Code) as Quant, m.Name as Model from Trace t JOIN CodePost cp on t.CodePost_id = cp.Id JOIN Post p on cp.Post_id = p.Id JOIN ConfigLine cl on p.ConfigLine_id = cl.Id JOIN Model m on cl.Model

  • Fetch child and parent - Laravel EloquentJanuary 15

    In laravel I have the below 2 models; This is the parent <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class RestaurantClass extends Model { /** * Get the restaurants for the restaurant class. */ public function restaurants() {

  • Laravel: eloquent relationship create multiFebruary 4

    i have a ParentItem model $parentItem = ParentItem::get()->first(); I have this array $items = array( array( 'title' => 'test1', 'desc' => 'test1' ), array( 'title' => 'test2', 'desc' => 'test2' ) ); i want to add it as a has many relations

  • Laravel Eloquent how to select relation field as certain fields of main objectFebruary 11

    $select = Model::with(['relation' => function($query) { $query->select('id', 'somefield'); }])->get(); When using this code I get my Model object with relation field which contains somefield. { ... some Model fields ... relation => { id =>

  • Reiterate through array and add to DB - Laravel/Eloquent/PHPFebruary 13

    I'm having difficulties retrieving an Eloquent model and lopping through it and then adding it to another table. So here is my query; $cart = Cart::with('cartItems','cartItems.cartModifierItems')->where(['vcode' => $code, 'cookie_id' => $cookie])

  • Error in setting up laravel Eloquent relationshipFebruary 14

    I am trying to set up a relationship in Laravel using the eloquent relationship model, it looks like the one below users id email projects id name user_projects user_id project_id role I want to be able to query the projects that the user is a part o

  • Laravel / Eloquent relationships & querying the databaseFebruary 14

    I'm having trouble with a particular eloquent query and can't for the life of me figure it out. I am trying to get an 8 bar preview of a beat that I have in my database, the beat is related like the following: Beat.TrackId->Track.id. The different ba

  • Laravel get relation count where a field in the database is set to a certain valueFebruary 17

    I have a Task model and a Step model. Each Task can have multiple steps. I want to be able to display all tasks including a progress bar. The length of the progress bar will be calculated by the total steps and the total steps that are completed. So

  • Optimizing Laravel Eloquent multiple joinsJune 26

    The following is working and readable SQL for Eloquent that I have created. The downside is that it looks more like a 1:1 with SQL and I don't think I'm using the full potential of Eloquent. I thought of using scope queries to shorten it, but for som

  • Laravel Eloquent Retrieving only certain rowsJanuary 23

    I have a number of models and I have the relationships set up correctly I believe. I want to retrieve all of the models from a table if and only if the active column of a foreign key table is true. I have tried a number of variations but to no avail.

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 11 q. 0.620 s.