Amaqhinga obuhlobo bobudlelwane beLaravel

Elinye lamandla kaLaravel sis syntax yayo entle. Ukuba uneemodeli ezininzi kunye nobudlelwane eLaravel (ngenxa yeetafile ezininzi kwindawo yogcino lwedatha), ukuwela kungaphelela kwikhowudi encinci. Ekuhambeni kwexesha, izandiso ezincinanana ezintathu ziye zangqina ngokwam, endinqwenela ukuzazisa ngokufutshane apha ngezantsi. Sisebenzisa nje ilifa elithile, iindlela zomlingo kunye nokuqokelelwa kwesiko.


Kuqala senza imodeli entsha phantsi kweapp \ ConvenienceModel.php:

b45e29b9125c2ab565b5526442437686

Emva koko siyeke zonke iimodeli zizuze kwilifa lethu elitsha ConvenienceModel:

b45e29b9125c2ab565b5526442437686

Hlanganisa imisebenzi yakho nobudlelwane

Ukuba ufuna ukudibanisa iimodeli, usebenzisa is syntax esemgangathweni ukubabiza:

b45e29b9125c2ab565b5526442437686

Ukuba ngoku wongeza eyakho i-logic yeshishini, uyathanda ukusebenzisa (ezantsi) ikota yeenkamela:

b45e29b9125c2ab565b5526442437686

Sifuna ukumisa umgangatho we-syntax yazo zombini ezi zinto zahlukileyo. Ukwenza oku, sidibanisa indlela yobugqi __call kwi ConvenienceModel:

b45e29b9125c2ab565b5526442437686

Le fowuni inokwenzeka kwakhona kumzekelo ongentla:

b45e29b9125c2ab565b5526442437686

Jonga izinto ezingenanto

Ukuba ufuna ukukhupha igama lelizwe kwidilesi yomntu, uya kuhlala ubona le khowudi ilandelayo:

b45e29b9125c2ab565b5526442437686

Ukuthintela oku, sibandakanya ilayibrari ye- stringhelper kwaye sibuyise into ekhethekileyo yodidi olungenanto ukuba imodeli ayifumaneki:

b45e29b9125c2ab565b5526442437686

Oku kukwenza ukuba umnxeba uphumelele (kulo mzekelo, ukuba kukho into efumanekayo, igama lelizwe liyaphuma, kuzo zonke ezinye iimeko umtya ongenanto).

b45e29b9125c2ab565b5526442437686

Ukuba sifuna ukugubungela ityala lokuba umsebenzisi one-ID 42 angabinakho nokubakho, sizokwakha nomsebenzi omncinci wokuncedisa koku:

b45e29b9125c2ab565b5526442437686

Lo mnxeba ulandelayo ke uhambisa umtya ongenanto nokuba umsebenzisi akakho kwaphela:

b45e29b9125c2ab565b5526442437686

Ukuhamba ngokulula n: m ubudlelwane

Okokugqibela, sifuna ukwenza lula le khowudi ilandelayo:

b45e29b9125c2ab565b5526442437686

Ngale nto sisebenzisa ukubakho kwengqokelela yesiko . Siqala ngokwandisa imodeli elula:

b45e29b9125c2ab565b5526442437686

Emva koko senza usetyenziso lwefayile \ AbancedisiConvenienceCollection.php , eqinisekisa ukuba ukubiza imisebenzi engaziwayo kwingqokelela kuqhuba umsebenzi wazo zonke izinto eziqokelelweyo:

b45e29b9125c2ab565b5526442437686

Ke singasebenzisa le khowudi ilandelayo ukuvelisa onke amagama awo onke amazwe kuzo zonke iidilesi zabo bonke abazali bomntu:

b45e29b9125c2ab565b5526442437686

Kodwa iifowuni ezinje ngezi zilandelayo zinokwenzeka:

b45e29b9125c2ab565b5526442437686

Hlela ngokweekholamu ezininzi

Oku kulandelayo kufowuna kuphela ngendawo , nangona inokuba yayingeyiyo le uyifunayo:

b45e29b9125c2ab565b5526442437686

Sandisa iConvenienceCollection yethu ukuze sikwazi ukuhlela ngeendlela ezininzi:

b45e29b9125c2ab565b5526442437686

Ngale nto sinokuhlela ingqokelela ngokweekholamu ezininzi nge:

b45e29b9125c2ab565b5526442437686

Ukuhlelwa okusemgangathweni

Sikwandisa ukuHlanganisa ngokuLula ngomnye umsebenzi oncedisayo:

b45e29b9125c2ab565b5526442437686

Ngoku unokunika imodeli nganye umsebenzi wokuhlela okusemgangathweni:

b45e29b9125c2ab565b5526442437686

Ke sinokuhlela ingqokelela nge:

b45e29b9125c2ab565b5526442437686

Amagama ezinto

Imodeli nganye isebenzisa indlela yokufumana i-Label (getName iyahluka ngokuxhomekeka kwimodeli):

b45e29b9125c2ab565b5526442437686

Ngale nto unokubonisa ngokukhawuleza kwaye ngokulula igama lento. Emva koko unokumilisela uhlobo lomncedisi weByLabel kwiConvenienceCollection:

b45e29b9125c2ab565b5526442437686

Iziphumo ezingenanto

Ukuba inyathelo eliphakathi alinanto, imisebenzi yeLaravel kuqala () kunye neyokugqibela () ihlala ibuyisa zero. Ke ngoko sazisa i-GetFirst () kunye ne-GetLast () ukuze le fowuni ilandelayo ihlale iphumelela:

b45e29b9125c2ab565b5526442437686

Ngale nto sibuyisela i-__empty_helper eyi __x eyamkelayo:

b45e29b9125c2ab565b5526442437686

Emva