亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

??
1. ??? ?? ?? ??
2. Eloquent ?? ?? ??
3. ?? ??? ?? ??(??? ??)
4. ??? ?? ? ???(?? ? ?)
5. ?? ???: Laravel API ??? ??(?? ????? ???)
6. ???? ? ??
? ??? ?? PHP ???? Laravel Eloquent ??? ??: ?? ?? ???? ????? ???? ???

Laravel Eloquent ??? ??: ?? ?? ???? ????? ???? ???

Oct 16, 2025 pm 06:48 PM

Laravel Eloquent ??? ??: ?? ?? ???? ????? ???? ???

? ?? ????? Laravel Eloquent?? ??? ?? ???? ????? ???? ??? ???? ?? ??? ???. ?? ????? ?? ?(?: ?? ??)? ???? ?? ?? ?? ??? ????? ??(?: ??? ? ?? ?? ??? ??? JSON ??? ???? ??)? ??? ? ????. ? ??????? ?? ??, ?? ??? ??? ??? ??? ?? ?? ??? ??? API ???? ?? ??? ?? ???? ?????.

1. ??? ?? ?? ??

Laravel?? ??? ??? ??? ? ????? ? ?? ???, ? ? ?? ?? ???(?: person_table ? Skill_table)? ?? ?? ???(person_skill ?? ?? ???)? ?????.

  • person_table : id, name_of_person ?? ?? ??? ?????.
  • Skill_table : id, name_of_skill ?? ?? ??? ?????.
  • person_skill(?? ???) : person_table_id, Skill_table_id? ???? ??? ??? ?????.

??? ??? ?? ??? ??? ??? ?? ????.

 {
  "ID": 1,
  "??": "???",
  "??": [
    "php",
    "? ??",
    "?? js",
    "??J"
  ]
}

2. Eloquent ?? ?? ??

??, Eloquent ???? ??? ??? ???? ????? ???. Person? Skill??? ? ?? ??? ??? ??? ?????.

?/??/Person.php

 <?php ?????? App\Models;

Illuminate\Database\Eloquent\Factories\HasFactory? ?????.
Illuminate\Database\Eloquent\Model? ?????.

??? Person? ??? ?????.
{
    HasFactory? ?????.

    ??? $table = &#39;person_table&#39;; // ??? ??? ???? ?????/**
     * ??? ?? ???? ??? ??? ????*/
    ?? ?? ??()
    {
        return $this->belongsToMany(Skill::class, 'person_skill', 'person_table_id', 'skills_table_id');
    }
}

?/??/Skill.php

 <?php ?????? App\Models;

Illuminate\Database\Eloquent\Factories\HasFactory? ?????.
Illuminate\Database\Eloquent\Model? ?????.

??? ?? ?? ??
{
    HasFactory? ?????.

    ??? $table = &#39;skills_table&#39;; // ??? ??? ???? ?????/**
     * Skill? Person ???? ??? ??? ????*/
    ???()
    {
        return $this->belongsToMany(Person::class, 'person_skill', 'skills_table_id', 'person_table_id');
    }
}

3. ?? ??? ?? ??(??? ??)

N 1 ?? ??? ???? ??? ????? with() ???? ???? ?? ?? ???? ?? ???? ???.

 ?\??\??? ?????.

// ?? ???? ?? ??? ?????. $persons = Person::with('skills')->get();

// ? ??? ??? ?? ?? // $person = Person::with('skills')->first();

? ??? ??? ? $persons? Collection ??? ??, ? Person ?? ?????? Skill ??? ????, ? ??? ??? ?? Skill ?? ????(?: id: 1, name: php ?)? ???? Collection???.

4. ??? ?? ? ???(?? ? ?)

??? ???? ?? ???? ????? ??? ?? ??? ?? ? ????. ? ?? ? ??? ?? ????? ?? ??? ???? ?? ??? ??? ??? ???? ???. ?? pluck() ???? map() ???? ???? ??? ? ????.

  • pluck('name') : ???? ? ?? ?????? ??? ??? ?? ???? ? ???? ???? ? ?????.
  • map(function (Person $person) { ... }) : ???? ? ??? ???? ?? ??? ???? ? ??? ???? ? ???? ???? ? ?????.

??? ?? ??? ???? ?? ?????.

 ?\??\??? ?????.

$persons = ??::with('skills')->get();

$formattedPersons = $persons->map(?? (?? $??) {
    ?? [
        'id' => $person->id,
        'name' => $person->name_of_person, // ?? ?? ??? name_of_person??? ?????.
        'skills' => $person->skills->pluck('name_of_skill')->toArray(), // ?? ??? ???? ??? ??];
});

// ??? JSON ???? ???? ?? ?? // return response()->json($formattedPersons);

// PHP?? ??? ???? ?? // $resultArray = $formattedPersons->toArray();

? ???? ??? ????.

  1. ?? Person::with('skills')->get()? ???? ?? ???? ?? ??? ?????.
  2. ?? ?? $persons ????? map() ???? ?????. ???? ? Person ??? ?? ??? ?????.
    • ID? ??? ???? ??? ?? ??? ?????.
    • $person->skills? Skill ?? ???? ?????.
    • $person->skills->pluck('name_of_skill')? ? Skill ????? ?? name_of_skill ??? ?? ???? ['php', 'laravel']? ?? ? ???? ?????.
    • .toArray()? ??? ???? PHP ?? ??? ?????.

????? $formattedPersons? ? ??? ??? ???? ???? ??? ???? ? ????.

5. ?? ???: Laravel API ??? ??(?? ????? ???)

?? ??? API ???? ??? ??? ??? ??? ????? ?? Laravel? API ???? ?? ??? ?????. ?? ?? ? ??? ??? ?? ?? ??? ????? Eloquent ??? ??? ?? JSON ??? ??? ? ????.

??? ??:

 PHP ?? make:??? PersonResource

?/Http/???/PersonResource.php

 <?php ?????? App\Http\Resources;

Illuminate\Http\Resources\Json\JsonResource? ?????.

PersonResource ???? JsonResource? ?????.
{
    /**
     * ???? ??? ?????.
     *
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerialized
     */
    ?? ?? toArray($request)
    {
        ?? [
            &#39;id&#39; => $this->id,
            'name' => $this->name_of_person, // ?? ?? ??? name_of_person??? ?????.
            'skills' => $this->whenLoaded('skills', function () {
                return $this->skills->pluck('name_of_skill')->toArray();
            }),
            // 'skills' => SkillResource::collection($this->whenLoaded('skills')), // ???? ? ??? ??? ??? ??? ??];
    }
}

?????? ??:

 ?\??\??? ?????.
App\Http\Resources\PersonResource? ?????.

PersonController ???? Controller? ?????.
{
    ?? ?? ???()
    {
        $persons = ??::with('skills')->get();

        return PersonResource::collection($persons);
    }

    ?? ?? ??($id)
    {
        $person = ??::with('skills')->findOrFail($id);

        ??? PersonResource($person)? ?????.
    }
}

whenLoaded('skills', ...) ???? ?? ??? ?? ??? ???? ?? ???? ????? ?????. ?? ??? ??? ???? ??? ?????.

6. ???? ? ??

  • N 1 ?? ?? : ??? ? ??? ?? ?? ?????? ??? ???? ???? ?? with() ???? ???? ?? ???? ?? ?????.
  • ??? ? ?? : Eloquent ??? ?? PHP ?? ?? Collection ??? ?????. ?? ??? ??? ?? toArray() ???? ???? ?? ?? ???.
  • ?? ?? : pluck() ? ?? ??? ???? ? ??? ?????? ?? ??(?: name ?? name_of_skill)? ???? ???.
  • ??? : map() ???? ??? ???? ????? ??? ?? ?? ???? ??? ??? ??? ??? ? ????.
  • API ??? : ??? ???????? API ??? ?? API ???? ???? ??? ?? ??? ?? ? ????? ?? ?? ???? ????? ?? ????.

?? ??? ?? Laravel Eloquent? ??? ???? ?? ?? ???? ????? ???? ???? ????? ??? ???? ?? ??? ??? ? ????.

? ??? Laravel Eloquent ??? ??: ?? ?? ???? ????? ???? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Stock Market GPT

Stock Market GPT

? ??? ??? ?? AI ?? ?? ??

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

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

???

??? ??

???
PHP?? ??? ??? ???? ???? ??? ?????? PHP?? ??? ??? ???? ???? ??? ?????? Sep 21, 2025 am 04:07 AM

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

PHP?? ??? ? ?? ? ???? ??? ?????? PHP?? ??? ? ?? ? ???? ??? ?????? Sep 21, 2025 am 12:30 AM

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

PHP?? ? ??? ???? ??? ?????? PHP?? ? ??? ???? ??? ?????? Sep 21, 2025 am 12:26 AM

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

PHP ?????? ?? ????? ???? ??? ?????? PHP ?????? ?? ????? ???? ??? ?????? Sep 21, 2025 am 01:28 AM

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

PHP? ???????? ???? ?????? ??? ?????? PHP? ???????? ???? ?????? ??? ?????? Sep 21, 2025 am 04:47 AM

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

PHP? ?? ??? ????`__call ()`?`__get ()`? ?? ?????. PHP? ?? ??? ????`__call ()`?`__get ()`? ?? ?????. Sep 20, 2025 am 12:50 AM

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

PHP?? ?? ??? ?? ??? ?????? PHP?? ?? ??? ?? ??? ?????? Sep 20, 2025 am 05:11 AM

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

PHP?? ??? zip ????? ??? ??? ?????? PHP?? ??? zip ????? ??? ??? ?????? Sep 18, 2025 am 12:42 AM

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

See all articles