Laravel Eloquent ??? 5 ?? ?? ??? ?????. 1. ??? ?? Hasone ? Solgsto; 2. ???? Hasmany? Solgsto? ?????. 3. ??? ??? ?? ??? ???? ?? ???? ????. 4. ?? ??? hasmanythrough? ?????. ??? ??? Morphto? Morphmany? ?????. ? ??? ???? ??? ???? ?????. ??? ??? ??? ???? ???? ??? ?????? ????? ??????.
? ?? ?? ?? : ?? ???

Laravel? ???? ORM? ????? ??? PHP? ?????? ??? ?????. Laravel ?? ???? ???? ?? ??? ??, ?? ?? ?? ????? ??? ?? ???? ?? ???? ??? ?????. ? ???? ?? ???? ?? ??? ?? ??? ??? ??? ??? ?????.
1. ??? ??
???? ? ???? ?? ???? ??? ??? ???? ?????? ? ??? ??????.

? : User
??? Profile
????.
?????? ??
// ??? ??? schema :: create ( 'user', function (blueprint $ table) { $ table-> id (); $ table-> String ( 'name'); $ table-> string ( '???'); $ table-> timestamps (); }); // ???? ??? schema :: create ( 'profiles', function (blueprint $ table) { $ table-> id (); $ table-> forexid ( 'user_id')-> ranstreated ()-> ondelete ( 'cascade'); $ table-> string ( 'Phone')-> nullable (); $ table-> text ( 'bio')-> nullable (); $ table-> timestamps (); });
?? ??
// user.php ?? ?? ??? () { return $ this-> hasone (profile :: class); } // profile.php ?? ?? ??? () { return $ this-> soldsto (user :: class); }
??
$ user = user :: find (1); echo $ user-> profile-> bio; // ?????? ???? ???? $ user-> profile ()-> create ([[ '??'=> '123-456-7890', 'bio'=> 'laravel ???' ]);
?? :
hasOne
?? ?? (profiles.user_id
)?? ?? ?? ?????.
2. ??? ??
?? ???? ?? ?? ?????? ? ?????.
? : User
??? ?? Posts
????.
?????? ??
// ??? ??? schema :: create ( 'posts', function (blueprint $ table) { $ table-> id (); $ table-> foraxid ( 'user_id')-> ranstreated (); $ table-> String ( 'title'); $ table-> text ( 'body'); $ table-> timestamps (); });
?? ??
// user.php ?? ?? ??? () { $ this-> hasmany (post :: class); } // post.php ?? ?? ??? () { return $ this-> soldsto (user :: class); }
??
$ user = user :: find (1); foreach ($ user-> post as $ post) { echo $ post-> ??; } // ???? ???? $ user-> posts ()-> create ([[ 'title'=> '? ? ?? ???', 'Body'=> 'Hello World' ]);
3. ??? ??
??? ?? ??? ?? ???? ?? ??? ? ?????. ?? ???? ?????.
? : User
?? Roles
? ??? Role
?? Users
?? ?? ? ????.
?????? ??
// ?? ??? schema :: create ( '??', ?? (blueprint $ table) { $ table-> id (); $ table-> String ( 'name'); $ table-> timestamps (); }); // role_user pivot ??? (?? Role_Users ??) schema :: create ( 'role_user', function (blueprint $ table) { $ table-> forexid ( 'user_id')-> ranstreated ()-> ondelete ( 'cascade'); $ table-> forexiD ( 'role_id')-> ranstreated ()-> ondelete ( 'cascade'); $ table-> primary ([ 'user_id', 'role_id']); });
?? ??
// user.php ?? ?? ?? () { return $ this-> soldstomany (?? :: class); } // ?? .php ?? ?? ??? () { return $ this-> soldstomany (user :: class); }
??
$ user = user :: find (1); foreach ($ user-> ??? $ ??) { echo $ role-> name; } // ??? ????? $ user-> roboles ()-> att // ?? ??? (?? ??) $ user-> roles ()-> sync ([1, 2, 3]); // ?? ??? (? : ?? ??? ?? ?? ??) $ user-> roles ()-> att
? : Laravel? ??? ???? ??? ?? (
role_user
)? ?? ??? ??? ???? ?????. ? ?? ??? ???? ??? ??? ? ????.
belongsToMany(Role::class, 'user_roles')
4. ?? ?? ??? ????
?? ??? ?? ? ??? ?????? ?? ??????.
? : Country
Users
?? ?? Posts
????.
?? ??
// country.php ?? ?? ??? () { return $ this-> hasmanythrough (post :: class, user :: class); }
?? :
-
countries
→users
(Country_id) →posts
(user_id)
??
$ country = country :: find (1); foreach ($ country-> ??? as $ post) { echo $ post-> ??; }
5. ??? ??
??? ?? ??? ?? ??? ?? ??? ?? ??????.
? : Post
? User
Image
?? ? ????.
?????? ??
// ??? ??? schema :: create ( 'images', function (blueprint $ table) { $ table-> id (); $ table-> String ( 'url'); $ table-> morphs ( 'imageable'); // imageable_type ? imagable_id? ???? $ table-> timestamps (); });
?? ??
// image.php ?? ?? imagable () { return $ this-> morphto (); } // post.php ?? ?? ??? () { $ this-> morphmany (image :: class, 'Imagable'); } // user.php ?? ?? ??? () { $ this-> morphmany (image :: class, 'Imagable'); }
??
$ post = post :: find (1); $ image = $ post-> images ()-> create ([ 'url'=> 'photo.jpg']); // ???? ???? ???? $ image = image :: find (1); $ ??? = $ image-> imageable; // ??? ?? ??? ????? ?????
??? : ??? ?? ? ??
??? ??? ?? ??? Laravel? ???? ??? ????.
// ??? ?? ?? ? return $ this-> soldsto (user :: class, 'author_id'); // ?? ??? ??? ?? ?? ? return $ this-> setmentSto (user :: class, 'author_id', 'uuid');
?? ?? ??
?? | ?? a? ?? | ?? b? ?? b |
---|---|---|
??? | hasOne(B::class)
|
belongsTo(A::class)
|
???? ?? | hasMany(B::class)
|
belongsTo(A::class)
|
?? ????? ?? | belongsToMany(B::class)
|
belongsToMany(A::class)
|
?? ?? ??? ???? | hasManyThrough(C::class, B::class)
|
- |
??? | morphMany() / morphTo()
|
???? ????? |
???? ??? Laravel ??? ???? ???? ?????. ?? ( hasOne
, hasMany
? belongsTo
)?? ???? ?? ??? ?? belongsToMany
? ??? ???? ?????.
????? ???? ??? ? ? ???? ??? ??? ??? ?????.
? ??? Laravel Eloquent ?? ????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

1. PHP ?? ?? ? ?? ?????? Laravel MySQL VUE/React ??? ? ?? ??? ???? ??? ?? ?? ??? ?? Laravel MySQL VUE/React ??? ? ?? ?????. 2. ???? ?? (REDIS), ?????? ???, CDN ? ??? ?? ???????. 3. ?? ???, CSRF ??, HTTPS, ???? ??? ? ?? ??? ??? ???????. 4. ? ??? ??, ?? ??, ??, ???, ?? ?? ? ?? ??? ??? ???? ? ? ??? ??? ?? ????.

? ??? ? ?? ??? ???? ??? ?? ?? ??? ???? ???? ???? Laravel ??? ???? ???? ??? ???? ?? ??????. ??? ???? ???? ??? ??? ?? ?? ??? ?? "???? ???? ???"? ??? ???? ??? ??? ???? ??? ??? ?? ??? ???? ????? ???? ?? ? ???? ??? ?? ??? ?? ? ? ??????. ??? ??? ?? ???? httpdelete ???? ?????? ?? ??? ?????.

? ??? LaravelliveWire ?? ??? ???? ???? ??? ? ? ??? ??? ?? ??? ??? ?? ??? ????? ???? ????? ??? ???? ?? ??????. ?? ??? (? : "user.name")? ???? ?? ??? ?? ??? ????? ?? ?? ??? ??? ???? ?????. ? ??? Laravel? Data_get ??? ??? ??? ???? ?? ??? ?? ??? ??? ?? ??? ??? ???? ???? ??? ??? ???? ???? ???? ??? ?????.

??? PHP ??? ??? ??? ?? ???? ??? ?? ????? ???????. Laravel? ?? ??? ???? ??? ? ? ???? ??? ??? ???? ?????? ?? ? ?? ?? ???? ?????. Symfony? ? ???? ??? ???? ?????. Codeigniter? ??? ??? ?? ??? ?? ??? ?? ????? ?????. 2. AI ??? ???? ????? ??? ??? ??, ???? ?? ?? (? : ???, ??, F1 ?), ??? ? ?? ?? ? ?? ??? ?? ???? ?? ??? ???? ???? ?? ??? ? ?? ???? ?? ?? ??? ????? ?? ???? ????? ?????? ??? ????? ???????. 3. ??? ?? ?? ????? ?? ??? ?????. AES? ?? ??? ???? ????? ?????.

PHP?? ?? ??? ???? ? ?? ?? ??? ????. 1. php.ini? ?? ??? ??; 2. ? ?? (? : Apache? Setenv ?? nginx? FastCGI_Param)? ??????. 3. PHP ?????? putenv () ??? ??????. ? ??? Php.ini? ????? ??? ???? ??? ???? ? ?? ??? ?? ???? ????? ???? Putenv ()? ?? ??? ?????. ?? ???? ?? ?? (? : php.ini ?? ? ?? ??)? ???? ????. ?? ?? ??? ??? ?? ??? ????? ???? ?? ????.

PHP ????? ?? ??? ??? ? ??? ??? CI (Continuous Integration) ????? ???? ? ????. 1. DockerFile? ???? ?? ???, ?? ??, ??? ?? ? ?? ??? ???? PHP ??? ?????. 2. Gitlabci? ?? CI/CD ??? ???? .gitlab-ci.yml ??? ?? ??, ??? ? ?? ??? ???? ?? ??, ??? ? ??? ?????. 3. PHPUNIT? ?? ??? ??? ??? ???? ?? ?? ? ???? ???? ????????. 4. Kubernetes? ?? ?? ?? ??? ???? ?? .yaml ??? ?? ?? ??? ?????. 5. Dockerfile ??? ? ??? ??? ??????

? ??? ?? ??? ???? ??? ?? ??? ??? ??? ???? ???? ?? ????? ?? ?????. ??? ?? ??? ???? ??? ??? ?? ???? ???? ???? "???? ???? ???"??? ?? ????, ??? ???? ???? ??? ??, ? URI? ?? ??? ???? ???? ????? ??? ? ?? ??? ?????. ???? ??? HTTP ??? ?? ?? ??? ?? ?? ?? ? ??? ???? ?????? ???? ??? ?? ??????? ?? ? ? ??? ?????.

? ????? Laravel ????? ???? ???? ??? ?? ?? ??? ?? ??? ??? ?? ?????. ??? ?? ??? ???? ??? ??? ?? ???? ???? ???? ??? ?? ???? ??? ??? ?? ??? ??? ???? ??? Laravel ?? ?? ?? ???? ????? ?????. ???,? ??? ?? ??? ???? ?? ????? ?? ?? ? ???? ???? ?? RESTFUL ??? ? ???? HTTPDELETE ???? ???? ?? ????.
