Memulai Web Development dengan Laravel - Instalasi Melalui Composer
Muhammad Arslan 14 April 2017
Laravel sebagai salah satu web framework yang cukup ngartis dimata web developer Indonesia, mempunyai cukup banyak oportuniti di dunia pengembangan aplikasi web Indonesia. Tidak jarang perusahaan yang membuka lowongan pekerjaan bagi mereka yang menguasai Laravel selain menguasai Java Sprint ataupun ASP.NET.
Tidak hanya mudah digunakan penggunanya pun beragam mulai dari yang sudah senior hingga lulusan SMK. Selain itu buku - buku yang membahas Laravel pun sudah cukup banyak ketimbang yang membahas Express.js atau Symfony. Hal ini dikarenakan Laravel mempunyai daya tarik khas yang dapat membuat web developer beralih menggunakan web framework ini.
Kali ini Codepolitan akan membahas sebagian kecil dari keunggulan Laravel yang sudah dikenal luas oleh banyak web developer di dalam negeri. Bagi kamu yang baru mulai ingin menguasai Laravel, seri tutorial ini akan sangat bermanfaat untuk kamu yang ingin bekerja menggunakan Laravel.
Persiapan dan Instalasi
Untuk memulai membuat aplikasi web dengan Laravel, kamu memerlukan sebuah web server dan database engine. Silahkan gunakan Apache2 dan MySQL untuk Laravel ini. Kemudian PHP yang dibutuhkan paling minimal adalah versi 5.6 untuk kompatibilitas dengan berbagai package Laravel yang telah disediakan.
Download terlebih dahulu Composer dari tautan https://getcomposer.org/composer.phar. Kemudiani taruhlah di direktori yang mudah kamu hafal. Misal simpan di /opt/phar. Lalu silahkan masuk ke direktori /var/www/html atau direktori lainnya yang akan digunakan untuk menyimpan proyek Laravel.
Misal sekarang kita simpan proyek Laravel ini di /var/www/html.
$ cd /var/www/html
$ php /opt/phar/composer.phar create-project --prefer-dist laravel/laravel laraweb
Melihat Struktur Folder Laravel 5.6
Ada dua direktori utama di dalam Laravel. Pertama folder Root dan App.
Root:
- app, berisi kode aplikasi seperti controller, model, dan lainnya
- bootstrap, berisi file yang akan dijalankan saat bootstraping dan konfigurasi autoloading
- config, berisi file konfigurasi
- database, berisi file - file migrasi untuk database
- public, berisi file - file image, Javascript, dan CSS
- resources, berisi file views, SASS, LESS, dan file statis lainnya
- routes, berisi route aplikasi untuk web, api, dan console
- storage, menyimpan file log, cache, dan file yang diupload oleh user
- tests, menyimpan file test untuk aplikasi yang kita kembangkan
- vendor, menyimpan direktori dan file dari dependensi Composer yang kita pasang
App:
- Console, menyimpan file yang digunakan untuk mendefinisikan Artisan command
- Events, direktori ini tidak ada secara default namun akan dibuatkan ketika kamu ingin menggunakan Laravel Event
- Exceptions, menyimpan file eksepsi yang kamu definisikan untuk aplikasi yang kamu kembangkan
- Http, menyimpan file controller, middleware, dan form request
- Jobs, menyimpan file yang berisi definisi jobs untuk digunakan Laravel Queue
- Listeners, direktori ini secara default tidak ada hanya akan dibuatkan ketika kamu menggunakan Laravel Listener
- Mail, menyimpan file template untuk E-Mail
- Notifications, menyimpan file yang berisi class untuk penggunaan Laravel Notification
- Policies, menyimpan file yang berisi konfigurasi policy untuk aplikasi kita
- Providers, menyimpan file yang berisi service provider untuk aplikasi kita
Melihat Perintah - Perintah Laravel Artisan
Berikut adalah daftar lengkap dari berbagai perintah Laravel yang dapat kamu gunakan untuk meningkatkan development time selama membuat aplikasi web dengan Laravel:
$ php artisan
Laravel Framework version 5.3.29
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
clear-compiled Remove the compiled class file
down Put the application into maintenance mode
env Display the current framework environment
help Displays help for a command
inspire Display an inspiring quote
list Lists commands
migrate Run the database migrations
optimize Optimize the framework for better performance
serve Serve the application on the PHP development server
tinker Interact with your application
up Bring the application out of maintenance mode
app
app:name Set the application namespace
auth
auth:clear-resets Flush expired password reset tokens
cache
cache:clear Flush the application cache
cache:table Create a migration for the cache database table
config
config:cache Create a cache file for faster configuration loading
config:clear Remove the configuration cache file
db
db:seed Seed the database with records
event
event:generate Generate the missing events and listeners based on registration
key
key:generate Set the application key
make
make:auth Scaffold basic login and registration views and routes
make:command Create a new Artisan command
make:controller Create a new controller class
make:event Create a new event class
make:job Create a new job class
make:listener Create a new event listener class
make:mail Create a new email class
make:middleware Create a new middleware class
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:notification Create a new notification class
make:policy Create a new policy class
make:provider Create a new service provider class
make:request Create a new form request class
make:seeder Create a new seeder class
make:test Create a new test class
migrate
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
notifications
notifications:table Create a migration for the notifications table
queue
queue:failed List all of the failed queue jobs
queue:failed-table Create a migration for the failed queue jobs database table
queue:flush Flush all of the failed queue jobs
queue:forget Delete a failed queue job
queue:listen Listen to a given queue
queue:restart Restart queue worker daemons after their current job
queue:retry Retry a failed queue job
queue:table Create a migration for the queue jobs database table
queue:work Start processing jobs on the queue as a daemon
route
route:cache Create a route cache file for faster route registration
route:clear Remove the route cache file
route:list List all registered routes
schedule
schedule:run Run the scheduled commands
session
session:table Create a migration for the session database table
storage
storage:link Create a symbolic link from "public/storage" to "storage/app/public"
vendor
vendor:publish Publish any publishable assets from vendor packages
view
view:clear Clear all compiled view files
Halaman default Laravel dapat kamu akses dengan mengakses URL http://localhost/laraweb/public/ dan kamu akan melihat halaman yang elegan.