Gyara kurakurai a cikin Laravel: Yadda ake Nemo da Gyara Kurakurai a cikin Laravel Aikace-aikacen

Gyara kuskure wani muhimmin bangare ne na Laravel tsarin ci gaba, yana ba ku damar fahimta da warware batutuwa a cikin aikace-aikacenku. Laravel yana ba da kayan aiki daban-daban da fasali don taimakawa tare da gyara kuskure, yana taimaka muku gano tushen kurakurai da magance su. Anan ga ainihin jagora akan gyara kuskure a cikin Laravel:

Nuna Saƙonnin Kuskuren

Laravel An saita yanayin haɓaka don nuna cikakken saƙon kuskure lokacin da kurakurai suka faru. Tabbatar cewa kana aiki a cikin yanayin ci gaba, kuma za a nuna saƙon kuskure kai tsaye a cikin mai bincike.

 

Yi amfani da dd() Aiki

Aikin dd()(juji da mutu) kayan aiki ne mai amfani don dubawa da nuna masu canji, tsararru, ko abubuwa yayin aiwatarwa. Kuna iya amfani da su dd() don bincika bayanai da bincika yanayin su.

$data = ['name' => 'John', 'age' => 25];  
dd($data);  

Lokacin cin karo da dd() aikin, Laravel zai dakatar da aiwatarwa kuma zai nuna cikakken bayani game da $data maɓalli.

 

Yi amfani da Log Files

Laravel yana ba da hanyoyin shiga bayanai da kurakurai a cikin fayilolin log. Kuna iya amfani da hanyoyi kamar info(), error(), debug(), da sauransu, don shiga yayin aiwatarwa. Ana adana fayilolin log a cikin storage/logs kundin adireshi.

 

Ga misali na amfani da log log in fayil Laravel

Da farko, tabbatar Laravel an saita don shiga saƙonni. Buɗe .env fayil ɗin kuma tabbatar LOG_CHANNEL an saita canjin zuwa 'daily' ko 'stack'(idan ba a riga an saita shi ba):

LOG_CHANNEL=daily

A cikin lambar ku, zaku iya amfani da Log facade don rubuta saƙonnin shiga. Ga misali

use Illuminate\Support\Facades\Log;  
  
public function example()  
{  
    Log::info('This is an information log message.');  
  
    Log::warning('This is a warning log message.');  
  
    Log::error('This is an error log message.');  
}  

A cikin wannan misalin, muna amfani da info(), warning(), da error() hanyoyin facade Log don shigar da nau'ikan saƙonni daban-daban. Kuna iya amfani da waɗannan hanyoyin don shigar da saƙonni a matakan log daban-daban.

Ta hanyar tsoho, Laravel ana adana rajistan ayyukan a cikin storage/logs kundin adireshi. Kuna iya samun dama ga fayilolin log a waccan adireshin don duba saƙon da aka shigar. Fayilolin log ɗin an tsara su ta kwanan wata.

Don rubuta saƙonnin shiga tare da ƙarin mahallin ko bayanai, zaku iya wuce tsararru azaman hujja ta biyu zuwa hanyoyin log ɗin.

Log::info('User created', ['user_id' => 1]);

A wannan yanayin, ƙarin bayanan mahallin(user_id = 1) za a haɗa su cikin saƙon log ɗin

Hakanan zaka iya ƙirƙirar tashoshi log log na al'ada kuma saita su a cikin config/logging.php fayil ɗin. Wannan yana ba ku damar raba rajistan ayyukan sassa daban-daban na aikace-aikacenku ko don amfani da saitunan ma'ajin log daban-daban.

 

Amfani Laravel Telescope

Laravel Telescope kayan aiki ne mai ƙarfi kuma mai dacewa don Laravel. Yana ba da hanyar yanar gizo don sa ido da nazarin buƙatun, tambayoyin bayanai, jerin gwano, da ƙari. Don amfani da Telescope, kuna buƙatar shigar da saita shi a cikin Laravel aikace-aikacen ku.

 

Yi amfani da Xdebug da Debugging IDE

Xdebug sanannen kayan aikin gyara ne da ake amfani dashi Laravel da sauran ayyukan PHP da yawa. Ta hanyar shigar da Xdebug da haɗa shi tare da IDE debugging kamar PhpStorm, zaku iya waƙa da bincika yanayin aiwatar da lambar PHP ɗinku, saita wuraren hutu, bincika masu canji, da amfani da wasu fasalolin gyarawa.

 

Tare da abubuwan da ke sama da kayan aikin da ke sama, zaku iya gyara kuskure da warware Laravel aikace-aikacenku cikin sauƙi.