WebSocket ya kawo sauyi yadda ake samun sadarwa ta zahiri a aikace-aikacen yanar gizo. Ta hanyar ba da damar ci gaba da sadarwa ta hanyoyi biyu tsakanin uwar garken da abokin ciniki, WebSocket yana buɗe damar gina aikace-aikace masu ƙarfi da mu'amala. A cikin wannan labarin, za mu jagorance ku ta hanyar shigarwa da daidaitawa WebSocket a cikin Laravel aikace-aikacen ta amfani da laravel-websockets
kunshin.
Me yasa WebSocket a ciki Laravel ?
WebSocket yana ba da fa'ida mai mahimmanci akan sadarwar HTTP ta al'ada, musamman don aikace-aikacen da ke buƙatar sabuntawa nan take da fasalulluka masu mu'amala. Tare da Laravel ' mayar da hankali kan kyawawan lambar da ayyukan abokantaka na haɓakawa, haɗawa WebSocket yana ƙara zama marar lahani.
Jagoran Mataki na Mataki
Bari mu nutse cikin tsari mataki-mataki na shigarwa da daidaitawa WebSocket a cikin Laravel aikace-aikacenku:
1. Shigar da Kunshin: Fara da shigar da laravel-websockets
kunshin. Bude naku terminal kuma gudanar da umarni mai zuwa:
composer require beyondcode/laravel-websockets
2. Kanfigareshan: Bayan an shigar da kunshin, buga fayil ɗin sanyinta ta amfani da umarni mai zuwa:
php artisan vendor:publish --tag=websockets-config
Wannan umarnin zai haifar da websockets.php
fayil ɗin daidaitawa a cikin kundin adireshin ku config
.
3. Database Migration: Gudun migration umarni don ƙirƙirar teburin bayanai masu mahimmanci don WebSockets:
php artisan migrate
4. Fara uwar WebSocket garken: Don fara WebSocket uwar garken, gudu:
php artisan websockets:serve
Ta hanyar tsoho, WebSocket uwar garken yana aiki akan tashar jiragen ruwa 6001. Kuna iya saita wannan a cikin websockets.php
fayil ɗin sanyi.
Haɗuwa WebSocket da Aikace-aikacenku
Tare da WebSocket uwar garken sama da aiki, za ku iya fara haɗa fasali na ainihi cikin Laravel aikace-aikacenku. Laravel yana ba da API ɗin Watsawa wanda ke aiki tare da WebSocket. Watsa abubuwan da suka faru ta amfani da Laravel saban syntax kuma bari WebSocket su gudanar da isar da abubuwan da suka faru na ainihin lokaci ga abokan ciniki.
Kammalawa
Haɗin kai WebSocket cikin Laravel aikace-aikacenku ta amfani da laravel-websockets
kunshin yana buɗe sabbin hanyoyi don ƙirƙirar fa'idodi masu ƙarfi da jan hankali na ainihin lokacin. Tare da bayyananniyar shigarwa da tsarin daidaitawa, zaku iya amfani da ƙarfin WebSocket don gina aikace-aikacen mu'amala waɗanda ke ba da sabuntawa nan take da haɓaka ƙwarewar mai amfani.