PHP code example of te7a-houdini / laravel-applicant
1. Go to this page and download the library: Download te7a-houdini/laravel-applicant 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/ */
te7a-houdini / laravel-applicant example snippets
//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']);
//create a record with default type of "applicant" and default status of "created"
//and both receiver_id & receiver_type are null
$user->appliesFor();
$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();
//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');
$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');
php
//User model applies for Group model
$user->appliesFor($group);
//Group model process application from User model
$group->processApplicationFrom($user,'accepted');