PHP code example of achyutn / laravel-helpers

1. Go to this page and download the library: Download achyutn/laravel-helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

achyutn / laravel-helpers example snippets




namespace App\Models;

use AchyutN\LaravelHelpers\Traits\HasTheSlug;

class Post extends Model
{
    use HasTheSlug;

    protected string $sluggableColumn = 'title';
}


namespace App\Models;

use AchyutN\LaravelHelpers\Traits\HasTheMedia;
use Spatie\MediaLibrary\HasMedia;

class Post extends Model implements HasMedia
{
    use HasTheMedia;
}


namespace App\Models;

use AchyutN\LaravelHelpers\Models\MediaModel;

class Post extends MediaModel
{
    //
}


namespace App\Models;

use AchyutN\LaravelHelpers\Models\MediaModel;

class Post extends MediaModel
{
    protected array $theMediaCollections = ['cover', 'gallery', 'profile'];
}

$post = Post::find(1);

echo $post->gallery(); // Gallery collection image
echo $post->big_gallery(); // Large gallery image
echo $post->profile(); // Profile collection image
echo $post->medium_profile(); // Medium profile image



namespace App\Models;

use AchyutN\LaravelHelpers\Traits\HasTheDashboardTraits;

class Post extends Model
{
    use HasTheDashboardTraits;
}

Schema::table('posts', function (Blueprint $table) {
    $table->timestamp('approved_at')->nullable();
    $table->timestamp('rejected_at')->nullable();
});

use AchyutN\LaravelHelpers\Traits\CanBeApproved;

class Post extends Model
{
    use CanBeApproved;
}

$post->setApproved();
$post->setRejected();
$post->setPending();

Post::withPending()->get();
Post::onlyPending()->get();
Post::withoutApproved()->get();
Post::withRejected()->get();
Post::onlyRejected()->get();
Post::withAll()->count();

class Post extends Model
{
    use CanBeApproved;

    public const APPROVED_AT = 'approved_time';
    public const REJECTED_AT = 'rejected_time';
}

Schema::table('articles', function (Blueprint $table) {
    $table->timestamp('inactive_at')->nullable();
});

use AchyutN\LaravelHelpers\Traits\CanBeInactive;

class Article extends Model
{
    use CanBeInactive;
}

$article->setInactive();
$article->setActive();

Article::withInactive()->get();
Article::onlyInactive()->get();
Article::withoutInactive()->count();

class Article extends Model
{
    use CanBeInactive;

    public const INACTIVE_AT = 'disabled_at';
}



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

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



echo(english_nepali('नेपाली', 'Nepali', 'en')); // Nepali
echo(english_nepali('नेपाली', 'Nepali', 'ne')); // नेपाली

use AchyutN\LaravelHelpers\Rules\LatitudeRule;

$request->validate([
    'latitude' => [new LatitudeRule()],
]);

use AchyutN\LaravelHelpers\Rules\LongitudeRule;

$request->validate([
    'longitude' => [new LongitudeRule()],
]);