Both sides previous revision Previous revision Next revision | Previous revision |
programming:phplaravel [2022/09/10 16:51] – [php.laravel laravel] admin | programming:phplaravel [2022/09/19 16:57] (current) – [laravel.Development] admin |
---|
===== php.laravel laravel===== | ===== php.laravel laravel===== |
| * good info start here https://www.honeybadger.io/blog/laravel-queues-deep-dive/ |
| * good site - model info https://freek.dev/2332-getting-information-about-all-the-models-in-your-laravel-app |
<WRAP left tip 80%> | <WRAP left tip 80%> |
php Artisan tinker example user: | php Artisan tinker example user: |
$methods = (new ReflectionClass('\App\Models\User'))->getMethods(); | $methods = (new ReflectionClass('\App\Models\User'))->getMethods(); |
| |
$u=User::->find(5); | $u=User::find(5); |
| |
show $u # show source | show $u # show source |
| |
App\Models\Role::create(['id' => 2, 'code' => "archivist",'name' => "Архивист"]); | App\Models\Role::create(['id' => 2, 'code' => "archivist",'name' => "Архивист"]); |
| |
| |
| Storage::disk('tinker')->put('users_roles.json', json_encode($data_u, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE)); |
| |
# execute code in tinker from file | # execute code in tinker from file |
include('/var/www/laravel/storage/app/tinker/update_users.php') | include('/var/www/laravel/storage/app/tinker/update_users.php') |
| |
| ####### - обновление роли |
| #найти пользователя |
| User::with(['roles:id,name'])->where('id','305')->get(['id','name']); |
| User::with('digitalCertificates','roles')->where('name','LIKE', '%Ворончихин%')->first() |
| User::with('Roles')->where('name','LIKE', '%Шестакова%')->get(['id','name']) |
| User::with('Roles:id,name')->where('name','LIKE', '%Долматова%')->first(['id','name']) |
| |
| |
| #Обновление |
| User::where('name','LIKE', '%тампель%')->first()->roles()->detach(Role::where(['code' => 'user'])->first()); |
| User::where('name','LIKE', '%Ворончихин%')->first()->roles()->syncWithoutDetaching(Role::where(['code' => 'user'])->first()); |
| User::find(450)->roles()->syncWithoutDetaching(Role::where(['code' => 'user'])->first()); |
| |
| |
| function addUser($uid) { |
| return User::find($uid)->roles()->syncWithoutDetaching(Role::where(['code' => 'user'])->first()); |
| } |
</code> | </code> |
++++ Get All Models| | ++++ Get All Models| |
<code BASH> | <code BASH> |
>>> include('/var/www/laravel/storage/app/tinker/update_users.php') | >>> include('/var/www/laravel/storage/app/tinker/update_users.php') |
| </code> |
| |
| |
| 4. check without role |
| <code PHP> |
| |
| |
| $data_u=[]; |
| |
| $results=User::with(['roles:id,name'])->get(['id','name']); |
| foreach($results as $k => $v) { |
| if ($v->roles->isEmpty()) { |
| array_push($data_u,("${v["id"]} ${v["name"]} -> ".$v->roles->pluck('name')->implode(','))); |
| } |
| }; |
| |
| Storage::disk('tinker')->put('users_roles.json', json_encode($data_u, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE)); |
| |
| |
| |
</code> | </code> |
++++ | ++++ |
==== laravel.Development ==== | ==== laravel.Development ==== |
* Laravel's Dependency Injection Container in Depth https://gist.github.com/davejamesmiller/bd857d9b0ac895df7604dd2e63b23afe | * Laravel's Dependency Injection Container in Depth https://gist.github.com/davejamesmiller/bd857d9b0ac895df7604dd2e63b23afe |
| * laravel queues https://www.honeybadger.io/blog/laravel-queues-deep-dive/#introduction-to-jobs-queues-and-workers |
* laracast - namespace https://laracasts.com/lessons/namespacing-primer | * laracast - namespace https://laracasts.com/lessons/namespacing-primer |
* laravel auth guard https://darkghosthunter.medium.com/laravel-making-your-own-passwordless-auth-guard-b7740c89adf8 | * laravel auth guard https://darkghosthunter.medium.com/laravel-making-your-own-passwordless-auth-guard-b7740c89adf8 |