===== 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
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' => "Архивист"]);
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
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());
}
++++ Get All Models|
# Get All models in laravel
# laravel - use Spatie\ModelInfo\ModelInfo; 🠖 https://freek.dev/2332-getting-information-about-all-the-models-in-your-laravel-app
function getAllModels($sub_folder = "")
{
$modelList = [];
if (!empty($sub_folder)) {
$path = app_path() . "/Models/" . $sub_folder;
} else {
$path = app_path() . "/Models";
}
$results = scandir($path);
foreach ($results as $result) {
if ($result === '.' || $result === '..') continue;
$filename = $result;
if (is_dir($path . "/" . $filename)) {
$modelList = array_merge($modelList, getAllModels($filename));
} else {
$modelList[] = substr($filename, 0, -4);
}
}
return $modelList;
};
getAllModels();
++++
++++ SQL create php tinker |
1. format sql
-- sql for format commands tinker
with q as
(select id,ad_department,ad_subdepartment,ad_position
from public.ad_check
where 1=1
and ad_status
and ( length(ad_department)>2 or length(ad_subdepartment)>2 or length(ad_position)>2)
-- and id in (72, 76, 114, 118, 186, 187, 201, 213, 221, 229, 242, 247, 280, 284, 287, 315, 319)
--and ARRAY_LENGTH(REGEXP_SPLIT_TO_ARRAY(name, '\s'), 1)>3
)
select id, format('updateUser($a,id: %s, update: [%s])'
,id
,array_to_string(
array[ case when length(ad_department)>2 then '"department" => "'||ad_department||'",' else '' end
,case when length(ad_subdepartment)>2 then '"subdepartment" => "'||ad_subdepartment||'",' else '' end
,case when length(ad_position)>2 then '"position" => "'||ad_position||'",' else '' end
,'"place_of_work_filled"=>true'
]
,' ')
)
from q;
2.format php for tinker
true])
{
$a=array_merge_recursive($a,array("id_".$id=>array(
User::where("id",$id)->first(["id","name","department"
,"subdepartment","position"
,"place_of_work_filled"])
,User::where("id",$id)->update($update)
,User::where("id",$id)->first(["id","name","department"
,"subdepartment","position"
,"place_of_work_filled"])
)
)
);
}
$data=[];
updateUser($data,id: 4, update: ["department" => "Управление информационных технологий"
,"position" => "Начальник управления"
, "place_of_work_filled"=>true]);
updateUser($data,id: 5, update: ["department" => "Управление информационных технологий"\
,"position" => "Начальник управления"
, "place_of_work_filled"=>true]);
...
#save result
Storage::disk('tinker')->put('users20220910.json', json_encode($data, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE));
3. execute tinker
>>> include('/var/www/laravel/storage/app/tinker/update_users.php')
4. check without role
$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));
++++
==== News ====
* news - https://protone.media/nl/blog/laravel-form-components-to-rapidly-build-forms-with-tailwind-css-and-bootstrap-4
==== laravel.Development ====
* 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
* laravel auth guard https://darkghosthunter.medium.com/laravel-making-your-own-passwordless-auth-guard-b7740c89adf8
* laravel json https://laravel.demiart.ru/laravel-mysql-json/
* https://flareapp.io/ignition - error page
* https://habr.com/ru/post/441946/ - api rest laravel
==== laravel.links ====
* 20 laravel resources https://kinsta.com/blog/laravel-tutorial/
* laravel 8 blog - https://github.com/guillaumebriday/laravel-blog
* пример готового блога -> содержание из markdown - https://github.com/christophrumpel/christoph-rumpel.com
* [[https://github.com/protonemedia/laravel-form-components|laravel-form-components]] - заготовка под формы на tailwind