Last active
October 18, 2017 23:46
-
-
Save uyab/0ab923c7bf296c9b8976202a016baf98 to your computer and use it in GitHub Desktop.
Skinny Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function store(Request $request) | |
{ | |
// 1. cek hak akses | |
// Laravel sudah menyediakan fungsinya, seharusnya tinggal dipanggil | |
$this->authorize('voucher.add.store'); | |
// 2. membuat direktori, sepertinya bisa dipakai di tempat lain, jadi lebih baik dijadikan helper | |
create_directory(public_path(date('Ymd'))); | |
// 3. menyimpan ke database | |
// Dalam dunia MVC murni ala kids jaman now, ini tugasnya Model | |
// Nanti kita akan menemui konsep Repository, Factory, dan design pattern lain yang akan membuat dunia MVC menjadi lebih baik | |
Voucher::createManyFromInput($request->all()); | |
// 4. menulis ke file | |
// 5. meng-generate random string | |
// Fungsi 4 dan 5 bisa dipindahkan pemanggilannya ke fungsi createManyFromInput() di dalam Model | |
return redirect('backend/voucher'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment