diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index f704b51..f6a2b40 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,9 +1,9 @@ blank_issues_enabled: false contact_links: - name: Documentation - url: https://appkit.coutts.io/packages/:package_name/docs + url: https://appkit.coutts.io/packages/lockable/docs about: View the documentation - name: Community - url: https://appkit.coutts.io/packages/:package_name/community + url: https://appkit.coutts.io/packages/lockable/community about: Ask the community for help diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index e41b1fb..ec91715 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -1,4 +1,4 @@ -name: Check & fix styling +name: Check & Fix Styling on: [push] @@ -20,4 +20,4 @@ jobs: - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: Fix styling \ No newline at end of file + commit_message: Fix styling diff --git a/.php_cs.cache b/.php_cs.cache index 6903dee..8b057a7 100644 --- a/.php_cs.cache +++ b/.php_cs.cache @@ -1 +1 @@ -{"php":"7.4.13","version":"2.17.3","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["const","method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"blank_line_after_opening_tag":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true},"hashes":{"tests\/database\/migrations\/2021_01_01_000000_create_articles_table.php":1906224168,"src\/Facades\/Lockable.php":1969634961,"src\/Lockable.php":3429273821,"src\/Traits\/Lockable.php":3743096533,"src\/LockableServiceProvider.php":1931141247,"tests\/database\/migrations\/2014_10_12_000000_create_users_table.php":2933585291,"tests\/database\/factories\/UserFactory.php":364335595,"tests\/Models\/User.php":1901976356,"tests\/LockableTest.php":2883837912}} \ No newline at end of file +{"php":"7.4.13","version":"2.17.3","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["const","method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"blank_line_after_opening_tag":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true},"hashes":{"tests\/database\/migrations\/2021_01_01_000000_create_articles_table.php":3885317590,"src\/Facades\/Lockable.php":1969634961,"src\/Lockable.php":3429273821,"src\/Traits\/Lockable.php":3743096533,"src\/LockableServiceProvider.php":1931141247,"tests\/database\/migrations\/2014_10_12_000000_create_users_table.php":2933585291,"tests\/database\/factories\/UserFactory.php":364335595,"tests\/Models\/User.php":1901976356,"tests\/LockableTest.php":2883837912,"tests\/database\/factories\/ArticlesFactory.php":2293051357,"tests\/Models\/Article.php":376444782,"tests\/TestCase.php":1479180223}} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fd83ef6..b2ea08a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -All notable changes to `:package_name` will be documented in this file +All notable changes to `lockable` will be documented in this file ## 1.0.0 - 201X-XX-XX diff --git a/README.md b/README.md index 7d14cf4..a042bb4 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,63 @@ -# Very short description of the package +# Eloquent Lockable -[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-appkit/:package_name.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/:package_name) -[![Build Status](https://img.shields.io/github/workflow/status/laravel-appkit/:package_name/Automated%20Tests?style=flat-square)](https://github.com/laravel-appkit/:package_name/actions?query=workflow%3A%22Automated+Tests%22) -[![Quality Score](https://img.shields.io/github/workflow/status/laravel-appkit/:package_name/Check%20&%20fix%20styling?label=code%20quality&style=flat-square)](https://github.com/laravel-appkit/:package_name/actions?query=workflow%3A%22Check+%26+fix+styling%22) -[![Total Downloads](https://img.shields.io/packagist/dt/laravel-appkit/:package_name.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/:package_name) -[![Licence](https://img.shields.io/packagist/l/laravel-appkit/:package_name.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/:package_name) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-appkit/lockable.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/lockable) +[![Build Status](https://img.shields.io/github/workflow/status/laravel-appkit/lockable/Automated%20Tests?style=flat-square)](https://github.com/laravel-appkit/lockable/actions?query=workflow%3A%22Automated+Tests%22) +[![Quality Score](https://img.shields.io/github/workflow/status/laravel-appkit/lockable/Check%20&%20fix%20styling?label=code%20quality&style=flat-square)](https://github.com/laravel-appkit/lockable/actions?query=workflow%3A%22Check+%26+fix+styling%22) +[![Total Downloads](https://img.shields.io/packagist/dt/laravel-appkit/lockable.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/lockable) +[![Licence](https://img.shields.io/packagist/l/laravel-appkit/lockable.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/lockable) -This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors. +Allows a user to acquire a lock on a model, which prevents anyone else from being able to edit it. ## Installation You can install the package via composer: ```bash -composer require laravel-appkit/:package_name +composer require laravel-appkit/lockable ``` ## Usage +Add the `AppKit\Lockable\Traits\Lockable` trait to the model you want to set locks on + +Add a `locked_by` integer column to the corresponding table. This can also be done using the `lockable` method on the migration. + ``` php -// Usage description here +acquireLock(); ``` +### Releasing Locks +To release the existing lock on a model, call the `releaseLock` method on it. +```php +$article->releaseLock(); +``` ### Testing ``` bash diff --git a/composer.json b/composer.json index f56880c..e17cd3d 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { - "name": "laravel-appkit/:package_name", + "name": "laravel-appkit/lockable", "description": "", "keywords": [ "laravel", "appkit", - ":package_name" + "lockable" ], - "homepage": "https://github.com/laravel-appkit/:package_name", + "homepage": "https://github.com/laravel-appkit/lockable", "license": "MIT", "type": "library", "authors": [ @@ -27,12 +27,12 @@ }, "autoload": { "psr-4": { - "AppKit\\:package_name_php\\": "src" + "AppKit\\Lockable\\": "src" } }, "autoload-dev": { "psr-4": { - "AppKit\\:package_name_php\\Tests\\": "tests" + "AppKit\\Lockable\\Tests\\": "tests" } }, "scripts": { @@ -42,10 +42,10 @@ "extra": { "laravel": { "providers": [ - "AppKit\\:package_name_php\\:package_name_phpServiceProvider" + "AppKit\\Lockable\\LockableServiceProvider" ], "aliases": { - ":package_name_php": "AppKit\\:package_name_php\\Facades\\:package_name_php" + "Lockable": "AppKit\\Lockable\\Facades\\Lockable" } } } diff --git a/config/config.php b/config/config.php index 94dae57..3a4d5a1 100644 --- a/config/config.php +++ b/config/config.php @@ -1,7 +1,7 @@ app = app(); - } - - // Build your next great package. -} diff --git a/src/PackageServiceProvider.php b/src/PackageServiceProvider.php deleted file mode 100644 index a054273..0000000 --- a/src/PackageServiceProvider.php +++ /dev/null @@ -1,60 +0,0 @@ -loadTranslationsFrom(__DIR__ . '/../resources/lang', ':package_name'); - // $this->loadViewsFrom(__DIR__ . '/../resources/views', ':package_name'); - // $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); - // $this->loadRoutesFrom(__DIR__ . '/../routes/:package_name.php'); - - if ($this->app->runningInConsole()) { - $this->publishes([ - __DIR__ . '/../config/config.php' => config_path(':package_name.php'), - ], 'config'); - - // Publishing the views. - /*$this->publishes([ - __DIR__ . '/../resources/views' => resource_path('views/vendor/:package_name'), - ], 'views');*/ - - // Publishing assets. - /*$this->publishes([ - __DIR__ . '/../resources/assets' => public_path('vendor/:package_name'), - ], 'assets');*/ - - // Publishing the translation files. - /*$this->publishes([ - __DIR__ . '/../resources/lang' => resource_path('lang/vendor/:package_name'), - ], 'lang');*/ - - // Registering package commands. - // $this->commands([]); - } - } - - /** - * Register the application services. - */ - public function register() - { - // Automatically apply the package configuration - $this->mergeConfigFrom(__DIR__ . '/../config/config.php', ':package_name'); - - // Register the main class to use with the facade - $this->app->singleton(':package_name', function () { - return new :package_name_php(); - }); - } -} diff --git a/src/Traits/.gitkeep b/src/Traits/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php deleted file mode 100644 index 48fc5f8..0000000 --- a/tests/ExampleTest.php +++ /dev/null @@ -1,23 +0,0 @@ -assertTrue(true); - } - - /** @test */ - public function artcilesCanBeLoaded() - { - // create 5 articles - factory(Article::class, 5)->create(); - - // check the database for 5 articles - $this->assertEquals(5, Article::count()); - } -} diff --git a/tests/Models/Article.php b/tests/Models/Article.php index 15ed0fc..f9c6c2a 100644 --- a/tests/Models/Article.php +++ b/tests/Models/Article.php @@ -1,11 +1,14 @@ :package_name_php::class + 'Lockable' => Lockable::class ]; } diff --git a/tests/database/factories/ArticlesFactory.php b/tests/database/factories/ArticlesFactory.php index 4a5f763..9df5db9 100644 --- a/tests/database/factories/ArticlesFactory.php +++ b/tests/database/factories/ArticlesFactory.php @@ -1,7 +1,7 @@ string('title'); $table->text('body'); $table->timestamps(); + $table->lockable(); }); }