PHP code example of csitc / real-rap
1. Go to this page and download the library: Download csitc/real-rap 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/ */
csitc / real-rap example snippets
> $users = User::all(['*'])->where([
> 'user_id <=' => 50]
> )->order([
> 'user_id' => 'desc',
> 'user_mobile' => 'desc'])
> ->limit(1)->getOne();
>
> class User extends Model{
>
> protected $table = 'inf_user';
>
> protected $primaryKey = 'user_id';
>
> protected $cast = [
> 'user_id' => 'integer',
> 'is_subscribed' => 'bool'
> ];
>
> protected $hidden = [
> 'agent_user',
> 'bank_real_name',
> 'is_subscribed',
> 'rebate_already_mentioned',
> 'rebate_being_mention',
> 'rebate_unmentioned',
> 'user_email'
> ];
>
> protected $attributes = [
> 'user_id' => 'id',
> ];
>
> }
>
> $user = User::findWhere([
> 'user_mobile' => '12381121695'
> ])->getOne();
> if($user){
> $user->user_mobile = '134234';
> $user->save();
> }
>
> User::findWhere(['user_mobile' => '18600908262'])->delete()
>
> \RealRap\RealRap::trans(function(){
> $user = new User();
> $user->user_mobile = '13345727773';
> $user->save();
> $user = new User();
> $user->user_mobile = '13347818106';
> $user->save();
> },function(){
> echo 'success';
> },function(){
> echo 'error';
> });
>
> $user = User::findWhere(['user_mobile' => '18600908262'])->getOne();
> if($user){
> print_r($user->delete() ? 'record delete success' : 'record delete failed');
> }else{
> print_r('record is not exists');
> }
>
$keys = $this->user->key
//The $keys is an array within objects or an object or null depends on the relation in User.php
User.php
class User extends Model
{
protected $table = 'inf_user';
protected $primaryKey = 'user_id';
protected function key(){
return $this->hasMany(Key::class,'cdk_bind_user');
//return $this->hasOne(Key::class,'cdk_bind_user');
}
}
Key.php
class Key extends Model
{
protected $table = 'inf_cd_keys';
protected $primaryKey = 'cdk_id';
}