{"id":15651685,"url":"https://github.com/mckenziearts/laravel-command","last_synced_at":"2025-04-30T17:21:47.099Z","repository":{"id":62526185,"uuid":"124028085","full_name":"mckenziearts/laravel-command","owner":"mckenziearts","description":"A Laravel package to provide artisan new commands","archived":false,"fork":false,"pushed_at":"2020-02-02T20:38:22.000Z","size":26,"stargazers_count":32,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T07:47:05.639Z","etag":null,"topics":["artisan-command","laravel","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mckenziearts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-06T05:53:13.000Z","updated_at":"2023-02-07T22:53:22.000Z","dependencies_parsed_at":"2022-11-02T11:01:18.314Z","dependency_job_id":null,"html_url":"https://github.com/mckenziearts/laravel-command","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mckenziearts%2Flaravel-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mckenziearts%2Flaravel-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mckenziearts%2Flaravel-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mckenziearts%2Flaravel-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mckenziearts","download_url":"https://codeload.github.com/mckenziearts/laravel-command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251749119,"owners_count":21637457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artisan-command","laravel","php"],"created_at":"2024-10-03T12:39:41.130Z","updated_at":"2025-04-30T17:21:47.054Z","avatar_url":"https://github.com/mckenziearts.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel-command\n\n[![Latest Stable Version](https://poser.pugx.org/mckenziearts/laravel-command/version)](https://packagist.org/packages/mckenziearts/laravel-command)\n[![License](https://poser.pugx.org/mckenziearts/laravel-command/license)](https://packagist.org/packages/mckenziearts/laravel-command)\n[![Build Status](https://scrutinizer-ci.com/g/Mckenziearts/laravel-command/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Mckenziearts/laravel-command/build-status)\n[![Total Downloads](https://poser.pugx.org/mckenziearts/laravel-command/downloads)](https://packagist.org/packages/mckenziearts/laravel-command)\n\n\nSimple package to quickly generate Laravel templated Repository, Helpers and Observer files.\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require mckenziearts/laravel-command --dev\n```\n\nFor Laravel 5.5 - you're done.\n\nFor Laravel 5.4 or 5.3 you'll only want to use these commands for ```local``` development, so you don't want to update the ```production``` providers array in ```config/app.php```. Instead, add the provider in ```app/Providers/AppServiceProvider.php```, like so:\n\n```php\npublic function register()\n{\n    if ($this-\u003eapp-\u003eenvironment() == 'local') {\n        $this-\u003eapp-\u003eregister('Mckenziearts\\LaravelCommand\\LaravelCommandServiceProvider');\n    }\n}\n```\n\n## Usage\n\nBy default Laravel does not allow to generate observers or even does not allow to take the notion of repository as Symfony. To generate its elements you can use the following commands\n\nOpen the console and enter this command to generate a new repository :\n\n```shell\nphp artisan make:repository {Entity}\n```\n\nThe generate file look like this :\n\n```php\nnamespace App\\Repositories;\n\nuse App\\Models\\Entity;\n\nclass EntityRepository\n{\n    /**\n     * @var Entity\n     */\n    private $model;\n\n    /**\n     * EntityRepository constructor.\n     * @param Entity $model\n     */\n    public function __construct(Entity $model)\n    {\n        $this-\u003emodel = $model;\n    }\n\n    /**\n     * Return a new instance of Entity Model\n     *\n     * @return Entity\n     */\n    public function newInstance()\n    {\n        return $this-\u003emodel-\u003enewInstance();\n    }\n}\n```\n\nBy default Repository load Model in the default application namespace `App\\Models` If your models are in another namespace, it will be necessary to change the use in the repository to have no error like :\n\n```php\nuse MODELS\\NAMESPACE\\Entity;\n```\n\nThis is the same action to perform for the observers, it also loads the models in the namespace App\\Models. To generate an observer, you must execute the command:\n\n```shell\nphp artisan make:observer {Entity}\n```\n\nThe generate file look like this :\n\n```php\nnamespace App\\Observers;\n\nuse App\\Models\\Entity;\n\nclass EntityObserver\n{\n    /**\n     * Trigger Before Create a Entity\n     *\n     * @param Entity $model\n     */\n    public function creating(Entity $model){}\n\n    /**\n     * Trigger after create a Entity\n     *\n     * @param Entity $model\n     */\n    public function created(Entity $model){}\n\n    /**\n     * Trigger before update a Entity\n     *\n     * @param Entity $model\n     */\n    public function updating(Entity $model){}\n\n    ...\n}\n\n```\n\n- Helper files\n\n``` bash\n$ php artisan make:helper {Entity}\n```\n\nThe generate file look like this :\n\n```php\nnamespace App\\Helpers;\n\nclass EntityHelper\n{\n\n}\n```\n\nIf you need better distribut your code, you can create a helper to put a logic to lighten your controllers.\n\nAn example of a helper that I often use in my projects\n\n```php\nnamespace App\\Helpers;\n\nuse Intervention\\Image\\Facades\\Image;\n\nclass MediaHelper\n{\n    /**\n     * @protected\n     *\n     * @var string $dir, the file uploaded path\n     */\n    protected static $dir = 'uploads';\n\n    /**\n     * @return string\n     */\n    public static function getUploadsFolder()\n    {\n        return self::$dir;\n    }\n\n    /**\n     * Return the size of an image\n     *\n     * @param string $file\n     * @param string $folder\n     * @return array $width and $height of the file give in parameter\n     */\n    public static function getFileSizes(string $file, string $folder = null)\n    {\n        if ($folder) {\n            list($width, $height, $type, $attr) = getimagesize(public_path(self::$dir.'/'. $folder .'/'.$file));\n        }\n        list($width, $height, $type, $attr) = getimagesize(public_path(self::$dir.'/'.$file));\n\n        return [\n            'width'     =\u003e $width,\n            'height'    =\u003e $height\n        ];\n    }\n\n    /**\n     * resize, To rezise and image\n     *\n     * @param string    $file      file to rezise\n     * @param int       $width     width of the file\n     * @param int       $height    height of the file\n     * @param string    $filepath  path to save file\n     */\n    public static function resize($file, $width, $height, $filepath)\n    {\n        Image::make($file)-\u003eresize($width, $height)-\u003esave($filepath);\n    }\n\n    /**\n     * getImageWeight\n     *\n     * @param $octets\n     * @return string\n     */\n    public static function getImageWeight($octets) {\n        $resultat = $octets;\n        for ($i = 0; $i \u003c 8 \u0026\u0026 $resultat \u003e= 1024; $i++) {\n            $resultat = $resultat / 1024;\n        }\n        if ($i \u003e 0) {\n            return preg_replace('/,00$/', '', number_format($resultat, 2, ',', ''))\n                . ' ' . substr('KMGTPEZY', $i-1, 1) . 'o';\n        } else {\n            return $resultat . ' o';\n        }\n    }\n\n}\n\n```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## License\n\nThe MIT License (MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmckenziearts%2Flaravel-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmckenziearts%2Flaravel-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmckenziearts%2Flaravel-command/lists"}