programming:phplaravel

This is an old revision of the document!


php Artisan tinker example user:

# $laravel artisan tinker 
# list all method of reflection 
$methods = (new ReflectionClass('\App\Models\User'))->getMethods();
 
$u=User::->find(5);
 
show $u # show source
dump $u # show data
show App\Models\User # show source code

 
$u=User::with(['digitalCertificates','roles'])->find(5);
 
# find user with releations and add role 
$u=User::with(['digitalCertificates','roles'])->find(8);
$u->roles()->save(App\Models\Role::find(2));
$u->refresh();
 
 
App\Models\Role::create(['id' => 2,   'code' => "archivist",'name' => "Архивист"]);
 
# execute code in tinker from file
include('/var/www/laravel/storage/app/tinker/update_users.php')

Get All Models

SQL create php tinker

  • programming/phplaravel.1662828600.txt.gz
  • Last modified: 2022/09/10 16:50
  • by admin