PHP code example of digitalcloud / eloquent-custom-actions
1. Go to this page and download the library: Download digitalcloud/eloquent-custom-actions 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/ */
digitalcloud / eloquent-custom-actions example snippets
class User extends Authenticatable
public function verify($mobile)
{
$userMobile = new UserMobile([
'mobile' => $mobile, 'status' => self::STATUS_VERIFIED
]);
if(app()->events->until(
event(new MobileVerifying($userMobile)) !== false
)){
$userMobile = $this->mobiles()->save($userMobile);
event(new MobileVerified($userMobile));
return $userMobile;
}
return false;
}
}
class User extends Authenticatable
{
public function actionVerify($mobile) {
return $userMobile = $this->mobiles()->save([
'mobile' => $mobile, 'status' => self::STATUS_VERIFIED
]);
}
}
class User extends Authenticatable
{
public function actionVerify($mobile) { }
protected $dispatchesEvents = [
'beforeVerify' => MobileVerifying::class,
'afterVerify' => MobileVerified::class
];
}
class User extends Authenticatable
{
public function actionVerify($mobile) { }
protected $observables = [
'beforeVerify', 'afterVerify'
];
}
namespace App\Observers;
use App\User;
class UserObserver
{
// Default eloquent actions
public function created(User $user){ }
// Custom eloquent actions
public function beforeVerify(User $user){ }
public function afterVerify(User $user){ }
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.