Showing posts with label Laravel 5.3. Show all posts
Showing posts with label Laravel 5.3. Show all posts

Wednesday, October 26, 2016

Laravel Paths

For laravel 5.3 :


Sunday, October 23, 2016

Create Package in Laravel 5.3 - Part I

So I have fresh laravel installation here... Then I'm gonna create a package example for my own need...:D
First let's create a new folder in our root directory, the folder name is "package" as shown below :
Next, let's create another folder inside of package. This folder will gonna be our name or vendor name then our package name [vendor or creator]/ [package name]
Next... let's add another folder called "src" :
Next,, open command prompt in windows, then go to that src folder, then type "composer init". Just follow the instruction :



Here is the result :
{my mistake, this composer.json should be outside of src folder >,<... So just move it outside like this :}

In order to make our package visible to laravel, we need to add some new config in laravel composer.json like this :
Execute "composer dump-autoload" to clear composer cache
Next is creating service-provider for our package,
Then... Move this HyosokaServiceProvider to src folder of our package :
Next,,, let's add HyosokaServiceProvider to laravel config provider :

Go to part II

Sunday, October 9, 2016

Simple Event-Listener Example in Laravel 5.3

So mmm....Let's create an event first by executing this command :
"php artisan make:event hisoka_event"
We will gonna see a new file in our events dir like this one :
Next... Create a listener for this event, type :
php artisan make:listener hisoka_listener --event="hisoka_event"
Result :

Next... let's register this event and it's listener to EventServiceProvider. Open eventServiceProvider.php in app/Providers/EvenServiceProvider.php, then add this line :
That will make our event and it's listener get connected each other, so when hisoka_event get's fired, hisoka_listener will gonna be executed...Next... Let's fire this event, we will gonna put it on a controller. For example here, it will be put on my HisokaController.php as shown below :
So we just need to trigger this controller when a link is clicked or another thing that we can use to do that... :D..... mmm... here I will just put it to a link like this :

Sooowh... The last thing we have to do is creating a route for hisoka_event :

Okiee... Let's try to run our awesome hisoka_event...
So when we click "Trigger hisoka event", our event will be executed and the route back to this page, but currently we can't see anything because we just put an empty event-listener here...wkwkwk...
So let's add this line to our listener :

Aaaand... let's hit the hisoka_event link again... then open laravel log... We'll gonna see our above log :


Soooo... That's all... Thank you for reading my post... ;)

Tuesday, October 4, 2016

Changing Default Timeout Value Laravel 5.3

Here is the error message for timeout :
That's happened because of this code :
So I just slept for 120 seconds and got timeout... This timeout value actually comes from php apache server, so if wanto change it, we can change it on php.ini file, but this way will gonna be changed globally. Aand if we just want to change the timeout value only for one process or class we can put this line on the top of each class like this :
We can use another method :
Both of these work... sooo... mmm... yaaaaps... that's all... :D

Monday, October 3, 2016

Contoh Task Scheduling di Laravel 5.3

Di sini kita akan bermain dengan task scheduling di laravel 5.3. So pertama-tama silahkan buat fresh laravel project... Terus kita buat command baru, pake perintah ini :
"php artisan make:console hisokaLog --command=hisoka:log"
Kita bakalan dapat file baru kek gini :
Eeeh... yg variabel $description itu bisa kita ganti jadi kek gini :
Terrrusss... command yg barusan kita buat ini didaftarin di array command di console kernel seperti terlihat di bawah :

Naaah... klu kita execute perintah "php artisan", kita bisa liad command yg barusan dibikin...
Yaaaaps.... berarti udah okieee... :D

Teruuus.... balik ke hisokaLog... didalam command hisokaLog kita ada method handle, naah method ini lah yang jadi inti dari command ini, jadi method handle ini bakalan selalu dieksekusi ketika commandnya dipanggil. So didalam handle ini kita bisa naro macem2 kyk ngirim email, cek status, cek database, dsb... di postingan ini kita bikin yang sederhana ajjah dulu, yaitu ngebuat log file... :D
Simple kaaan.... :D... Silahkan tambahkan kode berikut didalam handle method hisokaLog :

Naaah... terus kita eksekusi commandnya "php artisan hisoka:log"
Dan hasilnya bisa kita lihat difile log laravel di "storage-logs-laravel.log" :
Kereun kaaaah... wkwkkw... :D *ngasal... :D

Okiee... berikutnya adalah ngedaftarin commandnya ke task-scheduling... Jadi task scheduling dilaravel itu kyk loop yang selalu dieksekusi setiap periode waktu tertentu sesuai yang kita tentukan. So kembali ke file kernel sebelumnya dimana kita daftarin hisoka:log-nya, terus dibagian scheduling kita tambain kode ini :

Selese daaaah... :D... btw diatas kita pake schedulingnya everyMinute(), jadi setiap menit hisoka:command itu akan dipanggil/diexecute. Cumaaaaaan... itu klu udah diserver jadi tar dipanggil tiap menit, tapi karena kita dilokal environment, jadi execute schedulernya pake perintah "php artisan schedule:run".
 Jadi setelah beberapa kali jalanin schedule:run, laravel.log-nya jadi seperti ini :
Teruuusss...Untuk list lengkap scheduling method yg lain bisa dilihat dari dokumentasi laravel resminya kyk gini :

Sip sip... seperti ini ajjah contoh sederhana make Task Scheduling di laravel.... :)
Semoga bermanfaat... :)

Sunday, October 2, 2016

Creating Simple Rest API on Laravel 5.3

First step, lets install a new fresh laravel by executing this command on command prompt windows :
"composer create-project laravel/laravel simple-rest-api"

Okay...let's create a new controller :
Then add this method :
Last,.. add a new route for above method :
Doneee... We have successfully created a rest-api on laravel... :D
For testing it we use postman or soapUI... First let's use postman....
just enter this link on postman :
There you are... We can see that our response is there... So one thing to one in rest-api, we have to return an array from our method or we can use json response also like this :
This one will gonna give the same response like before.... Okaay... Next....is using soapUI...
Create a new project on soapUI



Aaand..... Tadaaaaa....

Okaaay... That's all for the first part, we are just using 'get' method here... :)

Go to the next part---post method---