All Projects → amaelftah → laravel-applicant

amaelftah / laravel-applicant

Licence: MIT license
Simple package to allow model applies and receives applications from other models

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-applicant

Workq
Job server in Go
Stars: ✭ 1,546 (+4887.1%)
Mutual labels:  job
Factotum
A system to programmatically run data pipelines
Stars: ✭ 158 (+409.68%)
Mutual labels:  job
Shardingsphere Elasticjob Cloud
Stars: ✭ 248 (+700%)
Mutual labels:  job
Awesome Job
优质开源内推项目,消除内推信息壁垒。
Stars: ✭ 1,528 (+4829.03%)
Mutual labels:  job
Aint Queue
🚀 An async-queue library built on top of swoole, flexable multi-consumer, coroutine supported. 基于 Swoole 的一个异步队列库,可弹性伸缩的工作进程池,工作进程协程支持。
Stars: ✭ 143 (+361.29%)
Mutual labels:  job
Resources
知名互联网企业内推资料整理 持续更新ing 。 目前已经维护五个微信群接近3000人,欢迎你的加入!
Stars: ✭ 1,910 (+6061.29%)
Mutual labels:  job
Jobfunnel
Scrape job websites into a single spreadsheet with no duplicates.
Stars: ✭ 1,528 (+4829.03%)
Mutual labels:  job
myprofile
Generate your resume easily from Github actions ✅ using discussion section 📃 🚀
Stars: ✭ 19 (-38.71%)
Mutual labels:  job
Jenkins Job Wrecker
convert Jenkins job XML to JJB YAML
Stars: ✭ 152 (+390.32%)
Mutual labels:  job
Forest
分布式任务调度平台,分布式,任务调度,schedule,scheduler
Stars: ✭ 231 (+645.16%)
Mutual labels:  job
Bull
Premium Queue package for handling distributed jobs and messages in NodeJS.
Stars: ✭ 11,748 (+37796.77%)
Mutual labels:  job
Jobwanted
找工作 (喜欢就赏颗星星呗!) 【演示地址】:http://job.haojima.net
Stars: ✭ 136 (+338.71%)
Mutual labels:  job
Saturn
The vip.com's distributed job scheduling platform.
Stars: ✭ 2,141 (+6806.45%)
Mutual labels:  job
Ytask
YTask is an asynchronous task queue for handling distributed jobs in golang(go异步任务框架)
Stars: ✭ 121 (+290.32%)
Mutual labels:  job
SpaceWar-ECS
A space war game made with ECS and JobSystem in Unity.
Stars: ✭ 26 (-16.13%)
Mutual labels:  job
Go Quartz
Simple, zero-dependency scheduling library for Go
Stars: ✭ 118 (+280.65%)
Mutual labels:  job
Node Rethinkdb Job Queue
A persistent job or task queue backed by RethinkDB.
Stars: ✭ 158 (+409.68%)
Mutual labels:  job
ets2-job-logger
ETS2 Job Logger
Stars: ✭ 15 (-51.61%)
Mutual labels:  job
nest-queue
Queue manager for NestJS Framework for Redis (via bull package)
Stars: ✭ 69 (+122.58%)
Mutual labels:  job
Javainterview
java中高级基础指南
Stars: ✭ 222 (+616.13%)
Mutual labels:  job

Releases Build Status StyleCI Code Quality License Downloads

Simple package to allow model applies and receives applications from other models.

for example it will allow you to do something like this:

//User model applies for Group model
$user->appliesFor($group);

//Group model process application from User model
$group->processApplicationFrom($user,'accepted');

Installation

You can install the package via composer:

composer require te7a-houdini/laravel-applicant

Then publish the configurations and migrations:

php artisan vendor:publish --provider="Te7aHoudini\LaravelApplicant\LaravelApplicantServiceProvider"

After the migration has been published then run the migrations to create required tables:

php artisan migrate

Usage

let's assume we have User model & Group model.

Using Applicant trait

to allow model behaves as applicant add Te7aHoudini\LaravelApplicant\Traits\Applicant trait to your model

use Illuminate\Foundation\Auth\User as Authenticatable;
use Te7aHoudini\LaravelApplicant\Traits\Applicant;

class User extends Authenticatable
{
    use Applicant;

    // ...
}

to make User model applies for Group model and creates a new application record in applications table . we can do this by different ways:

Using model for creating applications

if you didn't specify any application type or status. by default the type will be applicant and status wil be created

//create a record with default type of "applicant" and default status of "created" 
$user->appliesFor($group);

//create a record with type of "randomAppType" and default status of "created" 
$user->appliesFor($group, ['type' => 'randomAppType']);

//create a record with type of "randomAppType" and status of "randomAppStatus" 
$user->appliesFor($group, ['type' => 'randomAppType', 'status' => 'randomAppStatus']);

Using array for creating applications

in some cases you won't have a model object , but want to manually specify the attributes when creating application.

$user->appliesFor([
    'receiver_id' => 1,
    'receiver_type' => 'App\Models\Group',
]);

$user->appliesFor([
    'receiver_id' => 1,
    'receiver_type' => 'App\Models\Group',
    'type' => 'randomAppType',
    'status' => 'randomAppStatus',
]);

Using null for creating applications

if you don't want to specify a model for creating applications then no problem.

//create a record with default type of "applicant" and default status of "created" 
//and both receiver_id & receiver_type are null
$user->appliesFor();

Using hasAppliedFor()

if we want to check if model has made an application for another model. then we can achieve that with different ways.

note: like appliesFor() the hasAppliedFor() accepts same parameters

$user->hasAppliedFor($group);
$user->hasAppliedFor($group, ['type' => 'randomAppType', 'status' => 'randomAppStatus']);

$user->hasAppliedFor([
    'receiver_id' => 1,
    'receiver_type' => 'App\Models\Group',
]);

//check if $user model has application record with default type and status or not
$user->hasAppliedFor();

Using appliedApplicationsFor()

if you want to get current model applied applications you can do like this:

note: like appliesFor() the appliedApplicationsFor() accepts same parameters

$user->appliedApplicationsFor($group)->get();
$user->appliedApplicationsFor($group, ['type' => 'randomAppType', 'status' => 'randomAppStatus'])->get();

$user->appliedApplicationsFor([
    'receiver_id' => 1,
    'receiver_type' => 'App\Models\Group',
])->get();

Using appliedApplications()

this is a morphMany relation between current model and Application model

//returns \Illuminate\Database\Eloquent\Relations\MorphMany
$user->appliedApplications();

Using applicantCriteria Attribute

some models maybe applies for specific application type or status , so to make it easy for overriding default application type and status . just define applicantCriteria attribute in your model

use Illuminate\Foundation\Auth\User as Authenticatable;
use Te7aHoudini\LaravelApplicant\Traits\Applicant;

class User extends Authenticatable
{
    use Applicant;

    //you can define type or status or both
    $this->applicantCriteria = [
        'type' => 'randomAppType',
        'status' => 'randomAppStatus',
    ];
}

//instead of this.
$user->appliesFor($group, ['type' => 'randomAppType', 'status' => 'randomAppStatus']);
$user->hasAppliedFor($group,['type' => 'randomAppType', 'status' => 'randomAppStatus']);
$user->appliedApplicationsFor($group, ['type' => 'randomAppType', 'status' => 'randomAppStatus'])->get();

//you can now just remove the second param.
//and by default this will set the type to "randomAppType" and status to "randomAppStatus"
$user->appliesFor($group);
$user->hasAppliedFor($group);
$user->appliedApplicationsFor($group)->get();

Using setApplicantCriteria()

if you want to set the applicant criteria dynamically per model. you can do this.

//this will create a record with type of "randomAppType" and status of "randomAppStatus"
$user->setApplicantCriteria([
    'type' => 'randomAppType',
    'status' => 'randomAppStatus',
])->appliesFor($group);

Using ReceivesApplications trait

to allow model behaves as receiver add Te7aHoudini\LaravelApplicant\Traits\ReceivesApplications trait to your model

use Illuminate\Database\Eloquent\Model;
use Te7aHoudini\LaravelApplicant\Traits\ReceivesApplications;

class Group extends Model
{
    use ReceivesApplications;

    // ...
}

to make Group model process application from User model and update existing application record in applications table . we can do this by different ways:

Using model for processing applications

if you didn't specify any application type or status. by default will query of type will applicant and status of created

//update existing record with default status of "processed" .
$group->processApplicationFrom($user);

//instead of updating with default status of "processed" then it will get updated by "accepted" status.
$group->processApplicationFrom($user, 'accepted');

//query by type of "randomAppType" and update status to "processed" 
$group->processApplicationFrom($user, ['type' => 'randomAppType']);

//query by type of "randomAppType" and update status to "accepted" 
$group->processApplicationFrom($user, ['type' => 'randomAppType'], 'accepted');

//query by type of "randomAppType" and status of "randomAppStatus" 
$group->processApplicationFrom($user, ['type' => 'randomAppType', 'status' => 'randomAppStatus']);

//query by type of "randomAppType" and status of "randomAppStatus" and update status to "accepted"
$group->processApplicationFrom($user, ['type' => 'randomAppType', 'status' => 'randomAppStatus'], 'accepted');

Using array for processing applications

in some cases you won't have a model object , but want to manually specify the attributes when processing application.

$group->processApplicationFrom([
    'applicant_id' => 1,
    'applicant_type' => 'App\Models\User',
]);

$user->processApplicationFrom([
    'applicant_id' => 1,
    'applicant_type' => 'App\Models\User',
    'type' => 'randomAppType',
    'status' => 'randomAppStatus',
]);

//you can override the default status of "processed" by providing second param.
$group->processApplicationFrom([
    'applicant_id' => 1,
    'applicant_type' => 'App\Models\User',
], 'accepted');

Using hasReceivedApplicationFrom()

if we want to check if model has received an application from another model. then we can achieve that with different ways.

note: like processApplicationFrom() the hasReceivedApplicationFrom() accepts same parameters except the last parameter of newStatus

$group->hasReceivedApplicationFrom($user);
$group->hasReceivedApplicationFrom($user, ['type' => 'randomAppType', 'status' => 'randomAppStatus']);

$group->hasReceivedApplicationFrom([
    'applicant_id' => 1,
    'applicant_type' => 'App\Models\User',
]);

Using receivedApplicationsFrom()

if you want to get current model received applications you can do like this:

note: like processApplicationFrom() the receivedApplicationsFrom() accepts same parameters except the last parameter of newStatus

$group->receivedApplicationsFrom($user)->get();
$group->receivedApplicationsFrom($user, ['type' => 'randomAppType', 'status' => 'randomAppStatus'])->get();

$group->receivedApplicationsFrom([
    'applicant_id' => 1,
    'applicant_type' => 'App\Models\User',
])->get();

Using receivedApplications()

this is a morphMany relation between current model and Application model

//returns \Illuminate\Database\Eloquent\Relations\MorphMany
$user->receivedApplications();

Using receiverCriteria Attribute

some models maybe applies for specific application type or status , so to make it easy for overriding default application type and status . just define receiverCriteria attribute in your model

use Illuminate\Database\Eloquent\Model;
use Te7aHoudini\LaravelApplicant\Traits\ReceivesApplications;

class Group extends Model
{
    use ReceivesApplications;

    //you can define type or status or both
    $this->receiverCriteria = [
        'type' => 'randomAppType',
        'status' => 'randomAppStatus',
    ];
}

//instead of this.
$group->processApplicationFrom($user, ['type' => 'randomAppType', 'status' => 'randomAppStatus']);
$group->hasReceivedApplicationFrom($user,['type' => 'randomAppType', 'status' => 'randomAppStatus']);
$group->receivedApplicationsFrom($user, ['type' => 'randomAppType', 'status' => 'randomAppStatus'])->get();

//you can now just remove the second param.
//and by default this will query by type of "randomAppType" and status of "randomAppStatus"
$group->processApplicationFrom($user);
$group->hasReceivedApplicationFrom($user);
$group->receivedApplicationsFrom($user)->get();

Using setReceiverCriteria()

if you want to set the receiverCriteria criteria dynamically per model. you can do this.

//this will query by type of "randomAppType" and status of "randomAppStatus"
$user->setReceiverCriteria([
    'type' => 'randomAppType',
    'status' => 'randomAppStatus',
])->processApplicationFrom($group);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].