Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: achyutkneupane/laravel-helpers
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.2
Choose a base ref
...
head repository: achyutkneupane/laravel-helpers
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jan 3, 2024

  1. docs: Documentation with steps and badges (#6)

    * docs: Badges and installation command in README
    
    * docs: Installation Steps added
    achyutkneupane authored Jan 3, 2024
    Copy the full SHA
    59dae59 View commit details

Commits on Jan 22, 2024

  1. Copy the full SHA
    ffbe357 View commit details

Commits on Jan 23, 2024

  1. Copy the full SHA
    4ee38e3 View commit details
  2. Copy the full SHA
    9e92b08 View commit details
  3. Copy the full SHA
    9cd41d2 View commit details

Commits on Jan 29, 2024

  1. feat: Adds Custom Pagination Class And Api Base Controller (#11)

    * feat: added custom paginator class
    
    * feat: added api base controller
    Dipesh79 authored Jan 29, 2024
    Copy the full SHA
    dea5ee6 View commit details
  2. fix: BaseController extended from Illuminate (#12)

    * fix: BaseController replaced with Illuminate Controller
    
    * feat: Pagination registered in service provider
    achyutkneupane authored Jan 29, 2024
    Copy the full SHA
    598726e View commit details
  3. Copy the full SHA
    ee9cedb View commit details

Commits on Feb 4, 2024

  1. Copy the full SHA
    330a190 View commit details

Commits on Feb 5, 2024

  1. Copy the full SHA
    fcf96c2 View commit details
  2. Copy the full SHA
    e483f92 View commit details
  3. Copy the full SHA
    bc03546 View commit details
  4. Copy the full SHA
    9c2f323 View commit details
  5. Copy the full SHA
    326be98 View commit details
  6. Copy the full SHA
    8d60f48 View commit details
  7. Copy the full SHA
    cd22e1f View commit details
  8. Copy the full SHA
    29eb6b6 View commit details
  9. Copy the full SHA
    97d16f2 View commit details
  10. Copy the full SHA
    a3d5fa8 View commit details
  11. Merge pull request #17 from achyutkneupane/tests

    test: Test for all helpers and features added
    achyutkneupane authored Feb 5, 2024
    Copy the full SHA
    5d03561 View commit details

Commits on Feb 7, 2024

  1. feat: Adds Approved Scope

    Dipesh79 committed Feb 7, 2024
    Copy the full SHA
    363c5e5 View commit details
  2. Copy the full SHA
    b01227d View commit details
  3. test: Approval Test

    Dipesh79 committed Feb 7, 2024
    Copy the full SHA
    0d4bf51 View commit details
  4. fix: onlyPending typo fixed

    Dipesh79 committed Feb 7, 2024
    Copy the full SHA
    5e9b91b View commit details
  5. test: Approval Test

    Dipesh79 committed Feb 7, 2024
    Copy the full SHA
    df9876c View commit details
  6. Copy the full SHA
    8606b12 View commit details
  7. test: Approval Test

    Dipesh79 committed Feb 7, 2024
    Copy the full SHA
    aaf13da View commit details
  8. Copy the full SHA
    1fcf19b View commit details
  9. test: Approval Test

    Dipesh79 committed Feb 7, 2024
    Copy the full SHA
    853156d View commit details
  10. Copy the full SHA
    40bcd2a View commit details
  11. Copy the full SHA
    4af94c8 View commit details
  12. Copy the full SHA
    c742ce5 View commit details

Commits on Feb 9, 2024

  1. feat: Match Old Password Rule (#19)

    * feat: Adds Matchold Password Rule
    
    * test: Match Old Password Test
    Dipesh79 authored Feb 9, 2024
    Copy the full SHA
    46636b6 View commit details

Commits on Apr 10, 2024

  1. feat: Added Custom Error in API Base Controller (#20)

    feat: added new error function in base controller
    Dipesh79 authored Apr 10, 2024
    Copy the full SHA
    152a841 View commit details

Commits on Jun 18, 2024

  1. build: Laravel 11 support (#21)

    Laravel 11 support
    achyutkneupane authored Jun 18, 2024
    Copy the full SHA
    e60457e View commit details

Commits on Sep 10, 2024

  1. build: PHP Versions update (#22)

    * build: PHP 7.4 added
    
    * build: More than PHP 7.2 supported
    achyutkneupane authored Sep 10, 2024
    Copy the full SHA
    92e6d1e View commit details
  2. build: MediaLibrary Version downgrade (#23)

    * build: PHP 7.4 added
    
    * build: More than PHP 7.2 supported
    
    * Medialibrary version downgrade
    achyutkneupane authored Sep 10, 2024
    Copy the full SHA
    495b79f View commit details

Commits on Mar 9, 2025

  1. Copy the full SHA
    6c30bd6 View commit details
  2. Version update

    achyutkneupane committed Mar 9, 2025
    Copy the full SHA
    3336315 View commit details
Showing with 1,573 additions and 27 deletions.
  1. +3 −10 .github/workflows/master.yml
  2. +0 −1 .phpunit.result.cache
  3. +104 −0 README.md
  4. +20 −8 composer.json
  5. +42 −0 src/Controller/ApiBaseController.php
  6. +27 −0 src/LaravelHelperProvider.php
  7. +24 −0 src/Pagination/CustomPaginator.php
  8. +25 −0 src/Rules/LatitudeRule.php
  9. +25 −0 src/Rules/LongitudeRule.php
  10. +22 −0 src/Rules/MatchOldPassword.php
  11. +184 −0 src/Scope/ApprovedScope.php
  12. +114 −0 src/Scope/InactiveScope.php
  13. +117 −0 src/Traits/CanBeApproved.php
  14. +78 −0 src/Traits/CanBeInactive.php
  15. +1 −1 src/Traits/HasTheDashboardTraits.php
  16. +1 −1 src/Traits/HasTheMedia.php
  17. +1 −1 src/Traits/HasTheSlug.php
  18. +1 −1 src/nepali-helpers.php
  19. +70 −0 tests/ApproveActiveTest.php
  20. +82 −0 tests/ApproveTest.php
  21. +61 −0 tests/BaseTestCase.php
  22. +28 −0 tests/Factories/ApproveActiveFactory.php
  23. +28 −0 tests/Factories/ApproveFactory.php
  24. +29 −0 tests/Factories/ArticleFactory.php
  25. +30 −0 tests/Factories/UserFactory.php
  26. +32 −0 tests/InactiveTest.php
  27. +36 −0 tests/MatchOldPasswordTest.php
  28. +24 −0 tests/Models/Approve.php
  29. +27 −0 tests/Models/ApproveActive.php
  30. +24 −0 tests/Models/Article.php
  31. +21 −0 tests/Models/User.php
  32. +2 −4 tests/NepaliHelpersTest.php
  33. +22 −0 tests/Routes/LatLongRoutes.php
  34. +20 −0 tests/Routes/PasswordMatchRoutes.php
  35. +43 −0 tests/SlugTest.php
  36. +65 −0 tests/ValidationTest.php
  37. +35 −0 tests/migrations/approve_active_table.php
  38. +34 −0 tests/migrations/approves_table.php
  39. +37 −0 tests/migrations/articles_table.php
  40. +34 −0 tests/migrations/users_table.php
13 changes: 3 additions & 10 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -7,23 +7,16 @@ on:

jobs:
tests:
name: Run Tests
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: ['8.0']

name: PHP ${{ matrix.php }}

steps:
- name: Checkout Latest Codebase
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: 8.1
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none
@@ -32,4 +25,4 @@ jobs:
run: composer install --no-interaction --prefer-dist

- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,106 @@
# Laravel Helpers

[![Lint PR](https://github.com/achyutkneupane/laravel-helpers/actions/workflows/prlint.yml/badge.svg)](https://github.com/achyutkneupane/laravel-helpers/actions/workflows/prlint.yml)
[![Bump version](https://github.com/achyutkneupane/laravel-helpers/actions/workflows/tagrelease.yml/badge.svg)](https://github.com/achyutkneupane/laravel-helpers/actions/workflows/tagrelease.yml)
[![Latest Stable Version](http://poser.pugx.org/achyutn/laravel-helpers/v)](https://packagist.org/packages/achyutn/laravel-helpers)
[![Total Downloads](http://poser.pugx.org/achyutn/laravel-helpers/downloads)](https://packagist.org/packages/achyutn/laravel-helpers)
[![Dependents](http://poser.pugx.org/achyutn/laravel-helpers/dependents)](https://packagist.org/packages/achyutn/laravel-helpers)

## Installation

You can install the package via composer:

```bash
composer require achyutn/laravel-helpers
```

## Usage

### Traits

You can use following traits for your models:

#### `HasTheSlug`

This trait is used to generate slug for your model. It uses [cviebrock/eloquent-sluggable](https://github.com/cviebrock/eloquent-sluggable) package.

`Note: ` You must have `slug` column in your table and the source column for the slug should be `title`.

```php
<?php

namespace App\Models;

use AchyutN\Traits\HasTheSlug;

class Post extends Model
{
use HasTheSlug;
}
```

#### `HasTheMedia`

This trait is used to add media conversions over the `HasMedia` trait from [spatie/laravel-medialibrary](https://github.com/spatie/laravel-medialibrary) package.

```php

namespace App\Models;

use AchyutN\Traits\HasTheMedia;

class Post extends Model
{
use HasTheMedia;
}
```

You can use:
- `cover()` to get original image.
- `small_cover()` to get small image (in format: `WebP`).
- `medium_cover()` to get medium image (in format: `WebP`).
- `large_cover()` to get large image (in format: `WebP`).

#### `HasTheDashboardTraits`

This trait is used to add `HasTheSlug` and `HasTheMedia` traits to your model along with the `HasLog` trait from [Dipesh79/LaravelUserLogs](https://github.com/Dipesh79/LaravelUserLogs) package.

```php
<?php

namespace App\Models;

use AchyutN\Traits\HasTheDashboardTraits;

class Post extends Model
{
use HasTheDashboardTraits;
}
```

### Nepali Helpers

You can simply use following helper functions:

#### `english_nepali_number`

Converts english number to nepali number.

```php
<?php

echo(english_nepali_number('१ २३४५६७८०९', 'en')); // 1 234567890

echo(english_nepali_number('1 234567890', 'ne')); // १ २३४५६७८०९
```

#### `english_nepali`

To select value based on the locale.

```php
<?php

echo(english_nepali('नेपाली', 'Nepali', 'en')); // Nepali
echo(english_nepali('नेपाली', 'Nepali', 'ne')); // नेपाली
```
28 changes: 20 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -11,30 +11,42 @@
"src/helpers.php"
],
"psr-4": {
"AchyutN\\Traits\\": "src/Traits/"
"AchyutN\\LaravelHelpers\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"AchyutN\\LaravelHelpers\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Achyut Neupane",
"email": "achyutkneupane@gmail.com",
"homepage": "https://achyut.com.np",
"role": "Maintainer"
}, {
"name": "Dipesh79",
"email": "dipeshkhanal79@gmail.com",
"homepage": "https://khanaldipesh.com.np",
"role": "Developer"
}
],
"require": {
"php": "^8.0",
"dipesh79/laravel-user-logs": "^1.4.2",
"rap2hpoutre/laravel-log-viewer": "^2.3.0",
"spatie/laravel-medialibrary": "^11.0.3",
"cviebrock/eloquent-sluggable": "^10.0"
"php": ">7.2",
"dipesh79/laravel-user-logs": "^1.6.1",
"spatie/laravel-medialibrary": ">=8.0",
"cviebrock/eloquent-sluggable": ">=11.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0|^10.0"
"phpunit/phpunit": "^7.0|^8.0|^9.0|^10.0",
"orchestra/testbench": "^8.19"
},
"extra": {
"laravel": {
"providers": [
"AchyutN\\LaravelHelpers\\LaravelHelperProvider"
]
}
}
}
42 changes: 42 additions & 0 deletions src/Controller/ApiBaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace AchyutN\LaravelHelpers\Controller;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;

class ApiBaseController extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
public function api_success($data,$message)
{
return response()->json([
'status' => 200,
'data' => $data,
'message' => $message
], 200);
}

public function api_error($data)
{
Log::error($data);
return response()->json([
'status' => $data->getCode(),
'data' => [],
'message' => $data->getMessage()
], $data->getCode());
}

public function custom_error($status,$message)
{
return response()->json(
[
'status' => $status,
'data' => [],
'message' => $message
], $status
);
}
}
27 changes: 27 additions & 0 deletions src/LaravelHelperProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace AchyutN\LaravelHelpers;

use AchyutN\LaravelHelpers\Pagination\CustomPaginator;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

class LaravelHelperProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->app->alias(CustomPaginator::class, LengthAwarePaginator::class);
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
24 changes: 24 additions & 0 deletions src/Pagination/CustomPaginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace AchyutN\LaravelHelpers\Pagination;

use Illuminate\Pagination\LengthAwarePaginator;

class CustomPaginator extends LengthAwarePaginator
{
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray(): array
{
return [
'data' => $this->items->toArray(),
'total' => $this->total(),
'perPage' => $this->perPage(),
'page' => $this->currentPage(),

];
}
}
25 changes: 25 additions & 0 deletions src/Rules/LatitudeRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace AchyutN\LaravelHelpers\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class LatitudeRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!is_numeric($value)) {
$fail("The $attribute must be a number.");
}

if ($value < -90 || $value > 90) {
$fail("The $attribute must be between -90 and 90.");
}
}
}
25 changes: 25 additions & 0 deletions src/Rules/LongitudeRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace AchyutN\LaravelHelpers\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class LongitudeRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!is_numeric($value)) {
$fail("The $attribute must be a number.");
}

if ($value < -180 || $value > 180) {
$fail("The $attribute must be between -180 and 180.");
}
}
}
22 changes: 22 additions & 0 deletions src/Rules/MatchOldPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace AchyutN\LaravelHelpers\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Hash;

class MatchOldPassword implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!Hash::check($value, auth()->user()->password)) {
$fail('The old password does not match.');
}
}
}
Loading