how to use sum and groupBy in laravel consoletvs charts

$sumBrpro = DB::table(‘productions’) ->select([DB::raw(‘sum(montant_pro) as totalpro’),’branche’]) ->groupBy(‘branche’) ->get(); How can I pass a different value in consoletvs charts, this throws errors at index-> ​​branch. thank you for your help foreach($sumBrpro as $index){ $chartbr = Charts::create(‘bar’, ‘highcharts’) ->title(“production”) ->labels($index->branche) ->values($index->totalpro) ->dimensions(1000,500) ->responsive(true); } Vue <div> {!! $chartbr->html() !!} </div>“`

Is there a way to convert mysql to laravel eloquent query builder?

I want to obtain the first_check_in and last_check_out of an employee for the current day. The following MySQL code is working good but I am new to eloquent and I do not know how to write it. sorry for my English. SELECT `employees`.`*`, `teams`.`description`, `time_groups`.`start`, `time_groups`.`end`, cast(a1.action_time as date) AS date, Min(`a1`.`action_time`) AS `first_check_in`, MAX(`a2`.`action_time`)…

Is there a way to convert mysql to laravel eloquent query builder?

I want to obtain the first_check_in and last_check_out of an employee for the current day. The following MySQL code is working good but I am new to eloquent and I do not know how to write it. sorry for my English. SELECT `employees`.`*`, `teams`.`description`, `time_groups`.`start`, `time_groups`.`end`, cast(a1.action_time as date) AS date, Min(`a1`.`action_time`) AS `first_check_in`, MAX(`a2`.`action_time`)…

Why BelongsTo() isn’t working in Laravel 6?

I’ve got two Models User and AccountType class User extends Authenticatable { (…) public function accountType() { return $this->belongsTo(‘App\AccountType’, ‘account_type_id’, ‘id’); } } class AccountType extends Model { protected $table = ‘account_types’; // protected $primaryKey = ‘id’; public function users() { return $this->hasMany(‘App\User’); } } My database: Schema::create(‘users’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->bigInteger(‘account_type_id’)->unsigned(); $table->foreign(‘account_type_id’)->references(‘id’)->on(‘account_types’);…

Laravel: Selecting all films where the condiction is in another table

I have two models (“Films” and “Tags“) related in a Many to Many relation. I have therefore Three Tables: “films“, “tags” and “film_tag” EDITED: I have belongsToMany relations in place like this: film.php public function tags() { return $this->belongsToMany(‘App\Tag’, ‘film_tag’); } tag.php public function films() { return $this->belongsToMany(‘App\Film’); } I want to get a list…

Laravel BelongsTo Through relationship

How to implement BelongsToThrough Relationship in Laravel? I have Table: **projects_table** id **categories_table** id project_id **properties_table** id category_id Category BelongsTo Project public function project(){ return $this->belongsTo(‘App\Project’); } Property BelongsTo Category public function category(){ return $this->belongsTo(‘App\Category’); } How can we make a relationship? Property BelongsTo Project Through Category public function project(){ return $this->belongsToThrough(‘App\Project’, ‘App\Category’); } EDIT…

Laravel BelongsTo Through relationship

How to implement BelongsToThrough Relationship in Laravel? I have Table: **projects_table** id **categories_table** id project_id **properties_table** id category_id Category BelongsTo Project public function project(){ return $this->belongsTo(‘App\Project’); } Property BelongsTo Category public function project(){ return $this->belongsTo(‘App\Project’); } How can we make a relationship? Property BelongsTo Project Through Category public function project(){ return $this->belongsToThrough(‘App\Project’, ‘App\Category’); } EDIT…

Laravel Relate 2 models via intermediary table that has value

I have the following schema CREATE TABLE `attributes` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci | CREATE TABLE `records` ( `id` bigint(20) unsigned NOT NULL…