Laravel ?????? ????? ??? ??? ???? ?? ???? ?? ?????. ?? ??, "??"? ?? "??"? ?? ? ?? "??"? ?? ??? ??? ?? ????. ?? ??? ?? ??? ???? ?? ?? ??? ??? ??? ?? ??? ????? ?? ? ?? Eloquent ?? ? ??? ?? ??? ???? ???.
1. ??? ?? ?? ?? ??
??, Eloquent ??? ??? ??? ?? ???? ?????? ?????. Person? Skill??? ? ?? ??? ?? ???(?: person_skill)? ??? ?????.
?????? ??? ?? ?:
- person_table: id, name_of_person
- Skill_table: id, name_of_skill
- person_skill(?? ???): person_id, Skill_id
Eloquent ?? ?? ?:
Person ??? Skill ??? ??? ??? ?????.
// ?/??/Person.php ?????? App\Models; Illuminate\Database\Eloquent\Model? ?????. Illuminate\Database\Eloquent\Relations\BelongsToMany? ?????. ??? Person? ??? ?????. { ??? $table = 'person_table'; // ??? ??? ???? ?????. ?? ?? Skill(): BelongsToMany { return $this->belongsToMany(Skill::class, 'person_skill', 'person_id', 'skill_id'); } }
Skill ??? Person ??? ??? ??? ?????(?? ????? ???).
// ?/??/Skill.php ?????? App\Models; Illuminate\Database\Eloquent\Model? ?????. Illuminate\Database\Eloquent\Relations\BelongsToMany? ?????. ??? ?? ?? ?? { ??? $table = 'skills_table'; // ??? ??? ???? ?????. ?? ?? person(): BelongsToMany { return $this->belongsToMany(Person::class, 'person_skill', 'skill_id', 'person_id'); } }
2. N 1 ??? ??? ?? ?? ???? ?? ?????.
?? ??? ???? ??? ? ??? ?? ?? ???? ?? ???? ?? ?? ?? N1 ?? ??? ??? ??? ??? ??? ?? ? ??. ??? ??? ???? ?? ??? ?? ??(Eager Loading)? ?? Eloquent? with() ???? ???? ???.
?\??\??? ?????. // ?? ?? ? ?? ?? ??? ???? $persons = Person::with('skills')->get(); // ? ???? $persons? Person ??? ????? ? Person ???? ?? ?? ??? ???? ????. // ?? ?? $persons->first()->skills? ????? Skill ??? ??? ???? ???.
3. ?? ? ??? ?? ? ?? ??
Person::with('skills')->get()? ??? ?? ??? ?? Skill ?? ??(id, name_of_skill ?? ?? ?? ?? ??)? ???? ??????. ??? ??? ??? name_of_skill ??? ???? ??? ??? ???? ????.
Laravel ???? ????? ??? ?? ?? ?? ??? ? ?? pluck() ???? ?????. map() ???? ???? Person ???? ???? ? Person ??? ?? ??? ??? ? ????.
?\??\??? ?????. $persons = ??::with('skills')->get(); $formattedPersons = $persons->map(?? (?? $??) { ?? [ 'id' => $person->id, '??' => $person->name_of_person, 'skills' => $person->skills->pluck('name_of_skill')->toArray(), // pluck? ???? ?? ??? ???? ??? ??]; }); // $formattedPersons? ?? ?? ??? ???? ???? ??????. /* ?? ?($formattedPersons->toArray()? ?? ??): [ { "ID": 1, "??": "???", "??": [ "php", "? ??", "?? js", "??J" ] }, // ... ? ?? ?? ???] */
? ????:
- $persons->map(...)? Person ?? ???? ?????.
- ? Person ??? ?? ??? ?? ??? ?????.
- $person->skills? ?? ??? ?? ??? ??????.
- $person->skills->pluck('name_of_skill')? Skill ????? ?? name_of_skill ??? ?? ???? ? ???? ?????.
- .toArray()? ? ???? ??? ???? ?? ??? ???? ?? PHP ??? ?????.
4. Laravel API ???? ???? ?? ???
??? ??? ?? ??? ??? ? ??? API ???? ????? ?? Laravel? API ???? ? ???? ??? ??????. ?? ?? ??? ?? ??? ????? ???? ??? ??? ??? ??? ??? ? ????.
??? ??:
PHP ?? make:??? PersonResource PHP ?? make:??? SkillResource
SkillResource? ?????(??? ?? ????? PersonResource?? ?? ?????).
// ?/Http/Resources/SkillResource.php // ??? ??? ?? SkillResource?? ?? ?? ??? ???? ??? PersonResource?? ?? ???? ?? ?????. // ??? Skill? ???? ?? ?? ??? ?? ?? SkillResource? ??? ? ????. /* Illuminate\Http\Resources\Json\JsonResource? ?????. SkillResource ???? JsonResource? ?????. { ?? ?? toArray($request) { ?? [ 'id' => $this->id, '??' => $this->name_of_skill, // ...?? ?? ?? ??]; } } */
PersonResource ??:
// ?/Http/Resources/PersonResource.php ?????? App\Http\Resources; Illuminate\Http\Resources\Json\JsonResource? ?????. PersonResource ???? JsonResource? ?????. { /** * ???? ??? ?????. * * @param \Illuminate\Http\Request $request * @return ?? */ ?? ?? toArray($request) { ?? [ 'id' => $this->id, '??' => $this->_??? ??, 'skills' => $this->whenLoaded('skills', function () { return $this->skills->pluck('name_of_skill'); // ??? ?? ????. // SkillResource? ??? ?? ??? ?? ?? ????. // return SkillResource::collection($this->skills->pluck('name_of_skill')); // SkillResource?? ??? ????? ??}), ]; } }
?????? ??? ??:
// ?/Http/Controllers/PersonController.php ?????? App\Http\Controllers; ?\??\??? ?????. App\Http\Resources\PersonResource? ?????. Illuminate\Http\Request? ?????; PersonController ???? Controller? ?????. { ?? ?? ???() { $persons = ??::with('skills')->get(); //PersonResource::collection()? ???? ???? ?????. return PersonResource::collection($persons); } ?? ?? ?(Person $person) { // ?? Person? ?? Skill? ?????? ?????. $person->load('??'); ??? PersonResource($person)? ?????. } }
$this->whenLoaded('skills', ...)? ?? ??? ?? ??? ???? ??? ?? ??? ????? ???? ?? ??? ??? ?????. ??? ?? ???? ??? ???? ???? ?? ???? ?? ? ????.
5. ?? ?? ? ?? ??
- ?? ????? ?? with()? ??????. ?? ?? ???? ??? ? N 1 ?? ??? ??? ?????.
- ??? ?? ??: ??? ?? ??? ??? ?? map() ? pluck() ??? ?? ??????. ??? API ??, ??? ??, ?? ??? ?? ?? ? ?? ??? ?? ???? ???? API ???? ???? ?? ? ????.
- ?? ???: ?? ???? ?? ? ?? pluck() ??? ???? ???? ??? ? ????. ???? ???? ?????? ???? ?? ??? ?? ???? ??? ? ??? ???? ??????? Eloquent? ?? ?? ? ??? ??? ??????.
- ??? ??: ??, ?? ? ?????? ?? ???? ???? ???? ???? ??? ???? ?? ?? ???? ?? ??? ? ????.
??
? ????? ?? ??? Laravel Eloquent? with() ???? ???? ??? ??? ?? ???? ??? map() ? pluck() ???? ???? ?? ??? ?? ? ???? ???? ??? ????? ??? ?????. ??, API ??? ??? ??? ???? ????? ?? ?? ????? ??? ???? Laravel API Resources? ??? ???? ???????. ??? ??? ??? Laravel?? ??? ??? ??? ?? ????? ???? ???? ??? ? ?????? ? API? ???? ? ??? ???.
? ??? Laravel Eloquent: ??? ???? ?? ?? ?? ?? ???? ????? ?????.? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

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

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

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

Stock Market GPT
? ??? ??? ?? AI ?? ?? ??

?? ??

??? ??

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

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

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

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

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

usefilter_var () tovalidateemailsyntaxandcheckdnsrr () toverifydomainmxrecords.example : $ email = "user@example.com"; if (f ilter_var ($ ???, filter_validate_email) && checkdnsrr (Explode ( '@', $ email) [1], 'mx')) {echo "validandDeliverableEmail & qu

AseUnserialize (Serialize ($ obj))? AllDataisserializable ??? ?? FordeepCopying; ??? ???, ubstract__clone () tomanuallyduplicateNestEdObjectSandavoidshartReferences.

USEARRAY_MERGE () TOCOMBINEARRAYS, DUCRITINGDUPLICATESTRINGKEYSANDENTEXINGUMERICEYS; FORSIMPLERCONCATENATION, ?? ??? 55.6, USETHESPLATOPERATOR [... $ array1, ... $ array2].

?? ???? ? ?? ???? inphorganizecodecodecodeandnamingnamingconflictsbygroupingclasses, ?????, ??, andconstantsOnspecificname.2.defineanamesUsUsingThenamesPaceyWordAtTHETOPOFOFILE, AFFORBINSPACENAME, suchATESKEYSTOI

toupdateadaBasereCordInphp, FirstConnectusingpdoorMysqli, whenEseprepredStatementStoExecuteAcureCuresqlupDateQuery.example : $ pdo = newpdo ( "mysql : host = localhost; dbname = your_database", $ username, $ username, $ sql = "squer erestemail);

The__call ()? MethodsibleorundorundeRunded?? ?? ? ? MethodStrigged? ????, themodnameandarguments, asshowningwhendingderdefinedmethodslikesayhello ()

useathinfo ($ filename, pathinfo_extension) togetThefileExtension; itreliablyHandleSmultipledOtsededGecases, returningTheextension (? : "pdf") oranEmptyStringifnoneExists.

ziparchive ???? ???? zip ??? ????. ?? ?? ??? ??????? ??, AddFile? ???? ??? ????, ??? ?? ?? ??? ????, ?? ??? ?? ????? ????? ????? Call Call? ?? PHP? ?? ??? ??? ??????.
