Relational Metrics - lararvel package help you to make your metrics easier

Overview

logo

PHP Composer Run tests

Relational Metrics

This package will help you to make your metrics easier, You could get metrics about your Models, Models depending on their relations, or even metrics about your models depending on multiple conditions!!

It would be a very easy to get the number of your stores which has products has a price more than x$ ;)

1 - Dependency

The first step is using composer to install the package and automatically update your composer.json file, you can do this by running:

composer require syrian-open-source/laravel-relational-metrics

Usage

The Basic Usage of this package is the same of getting count of some model instances, but with a styled response

getBasicMetrics(); // or you can get the count or the message directly. $directCount = $instance->getCount(); $directName = $instance->getName(); /* * Response will be like: * [ * 'name' => 'Total Stores Number, * 'count' => 43, * ]; * */">
        $instance = (new \SOS\RelationalMetrics\Classes\RelationalMetrics("ModelName")); 
        // example: (new \SOS\RelationalMetrics\Classes\RelationalMetrics("Store"));
        // or you can specify thr model name by this way:  new RelationalMetrics(Store::class);
        $metrics = $instance->getBasicMetrics();
        // or you can get the count or the message directly.
        $directCount = $instance->getCount(); 
        $directName = $instance->getName(); 

        /*
	  *     Response will be like:
	  *	[
	  *	    'name' => 'Total Stores Number,
	  *	    'count' => 43,
	  *	];
	  *	
        */

What you can do next, you could get the metrics of a model depending on one of its relations!

Let's assume we want to get the number of stores that has products with price more than 500

getRelationalMetrics($relationName, $relationColumn, $value); // example: $instance->getRelationalMetrics('products, 'price', 500); /* * Response will be like: * [ * 'name' => 'Total Stores Number, * 'count' => 12, * ]; * */">
        $instance = (new \SOS\RelationalMetrics\Classes\RelationalMetrics("ModelName")); 
        // example: (new \SOS\RelationalMetrics\Classes\RelationalMetrics("Store"));
        // or you can specify thr model name by this way:  new RelationalMetrics(Store::class);
        $metrics = $instance->getRelationalMetrics($relationName, $relationColumn, $value);
        // example: $instance->getRelationalMetrics('products, 'price', 500);
        /*
	  *     Response will be like:
	  *	[
	  *	    'name' => 'Total Stores Number,
	  *	    'count' => 12,
	  *	];
	  *	
        */

At the previous Example the Package will return the number of the stores which has products with price equals to 500

And last but not least, You could get the metrics about a model depending on any number of conditions you want!

'where', 'column' => 'address', 'operator' => 'like', 'value' => '%UAE%'], ['method' => 'where', 'column' => 'rate', 'operator' => '>', 'value' => 3], ]; $metrics = $instance->getRelationalMetrics($conditions); /* * Response will be like: * [ * 'name' => 'Total Stores Number, * 'count' => 2, * ]; * */">
        $instance = (new \SOS\RelationalMetrics\Classes\RelationalMetrics("ModelName")); 
        // example: (new \SOS\RelationalMetrics\Classes\RelationalMetrics("Store"));
        // or you can specify thr model name by this way:  new RelationalMetrics(Store::class);
        // example for the conditions
        $conditions = [
                  ['method' => 'where', 'column' => 'address', 'operator' => 'like', 'value' => '%UAE%'],
                  ['method' => 'where', 'column' => 'rate', 'operator' => '>', 'value' => 3],
        ];
        $metrics = $instance->getRelationalMetrics($conditions);
        	
        /*
	  *     Response will be like:
	  *	[
	  *	    'name' => 'Total Stores Number,
	  *	    'count' => 2,
	  *	];
	  *	
        */

At the previous Example the Package will return the number of the stores where their address contains "UAE" and their rate is more than 3

Changelog

Please see the CHANGELOG for more information about what has changed or updated or added recently.

Security

If you discover any security related issues, please email them first to [email protected], if we do not fix it within a short period of time please open a new issue describing your problem.

Credits

Package Logo by

About Syrian Open Source

The Syrian Open Source platform is the first platform on GitHub dedicated to bringing Syrian developers from different cultures and experiences together, to work on projects in different languages, tasks, and versions, and works to attract Syrian developers to contribute more under one platform to open source software, work on it, and issue it with high quality and advanced engineering features, which It stimulates the dissemination of the open-source concept in the Syrian software community, and also contributes to raising the efficiency of developers by working on distributed systems and teams.

You might also like...
this package can help you to test race condition in Laravel Feature Test
this package can help you to test race condition in Laravel Feature Test

Laravel Async Testing this package can help you to test race condition in Laravel Feature Test Requirements Laravel versions 5.7, 6.x, 7.x and 8.x PHP

a Laravel package help you to execute more effective databases queries.
a Laravel package help you to execute more effective databases queries.

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimizing sql queries, this package will contain all advanced sq

This package should help you with creating and managing a Laravel DDD Application

This package should help you with creating and managing a Laravel DDD Application. This package is heavily inspired by "Laravel beyond CRUD" from Spatie.

This package gives you a set of conventions to make the most out of Hotwire in Laravel

Introduction This package gives you a set of conventions to make the most out of Hotwire in Laravel (inspired by the turbo-rails gem). There is a comp

This package provides you with a simplistic `php artisan make:user` command

Laracademy Generators Laracademy make:user Command - provides you with a simplistic artisan command to generate users from the console. Author(s): Lar

If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin
If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

hirwa-products-plugin If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

A package to easily make use of Iconic icons in your Laravel Blade views.
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

A package to easily make use of Simple Icons in your Laravel Blade views.
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

A package that makes it easy to have the `artisan make:` commands open the newly created file in your editor of choice.

Open On Make A package that makes it easy to have the artisan make: commands open the newly created file in your editor of choice. Installation compos

Comments
  • Using facades

    Using facades

    The package depending should be called from facades classes, In order to hide the complexity of dependencies

    example: instead of using the direct classes

        $instance =   (new \SOS\RelationalMetrics\Classes\RelationalMetrics("ModelName"));
    

    we can use it from the facade class

        $instance =   (new \SOS\RelationalMetrics\Classes\RelationalMetricsFacade())->setModel("ModelName")
                             ->getRelationalMetrics()
                             ->getCount();
    
    
    enhancement 
    opened by karam-mustafa 1
  • Class response best practice

    Class response best practice

    RelationalMetrics shoud return the values by getters also

    example: insead of get the count in this way

        $count = $instance->getBasicMetrics()['count'];
    

    we should able to get the count from a getter function like getCount();

       $count =  $instance->getBasicMetrics()->getCount();
    

    this will make the class more cohesion

    enhancement 
    opened by karam-mustafa 0
  • Get the results by trait in model

    Get the results by trait in model

    I think we can handle the logic for a custom model by adding trait in the model.

    example: instead of using the package in the follwing way

     $instance = (new \SOS\RelationalMetrics\Classes\RelationalMetrics("Store")); 
     $metrics = $instance->getBasicMetrics();
    

    we can get the same result as this example:

    $metrics = Store::getBasicMetrics();
    

    and the getBasicMetrics function should be able to call statically or from a new instance of the model

    enhancement 
    opened by karam-mustafa 0
Releases(v1.2.0)
Owner
Syrian Open Source
An open source platform that contains everything that was launched by Syrian developers and everything we think is interesting to publish.
Syrian Open Source
Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Laravel Testing Helper for Packages Development Testbench Component is the de-facto package that has been designed to help you write tests for your La

Orchestra Platform 1.9k Dec 29, 2022
You already have your dream house? Sam Building will help you find the perfect home.

SAM BUILDING Setup Fork or clone this repo! git clone github.com/Igorballo/Real-Estate-App.git Installation des dépendances npm install #or yarn insta

null 4 Nov 29, 2022
Electrik is a full-featured, open-source, starter-kit to help you build you your SaaS application.

Electrik Electrik is a full-featured and open-source stater-kit for for your next SaaS application. It's built on top of Laravel, Livewire, neerajsoha

Electrik 129 Dec 31, 2022
Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Label84 16 Nov 23, 2022
This package aims to help you standardize all your API responses in a simple and structured way.

Laravel API Response This package aims to help you standardize all your API responses in a simple and structured way. By default, the stucture of the

Kode Pandai 6 Dec 6, 2022
Export Laravel Horizon metrics using this Prometheus exporter.

Laravel Horizon Prometheus Exporter Export Laravel Horizon metrics using this Prometheus exporter. This package leverages Exporter Contracts. ?? Suppo

Renoki Co. 22 Sep 18, 2022
Export Laravel Octane metrics using this Prometheus exporter.

Laravel Octane Prometheus Exporter Export Laravel Octane metrics using this Prometheus exporter. ?? Supporting If you are using one or more Renoki Co.

Renoki Co. 19 Dec 26, 2022
👻 It's never been easier to build and customize admin panels. Yah! yaldash is a beautifully designed administration panel for Laravel.

?? It's never been easier to build and customize admin panels. Yah! yaldash is a beautifully designed administration panel for Laravel.

Yasser A.Idrissi 396 Dec 30, 2022
Laravel lsp - Developer tools for easier Laravel development

Laravel lsp The Laravel/Blade lsp provides: Blade: Diagnostics on missing components + action to create it. Autocomplete for components and their argu

Harings Rob 32 Dec 21, 2022
Makes working with DateTime fields in Laravel's Nova easier

This package adds a DateTime field with support for a global DateTime format, syntactic sugar for formatting individual DateTime fields and powerful d

wdelfuego 6 Aug 4, 2022