2. Hello!
Wahyu Rismawan
Informatics Eng, Telkom University (2011)
Software Artisan at Badr Interactive
~3 years exp in Web Development
Stalk:
Linkedin: bit.ly/wrismawan
FB: fb.com/wahyu.rismawan
14. Small Intro into MVC (Model-View-Controller)
Image source: http://www.meteorfury.com/2014/04/objective-c/model-view-controller-mvc-design-pattern/
15. Small Intro into MVC (Model-View-Controller)
Image source: http://www.meteorfury.com/2014/04/objective-c/model-view-controller-mvc-design-pattern/
“Model” Example
Directory for “Controller codes”
Directory for “View codes”
21. Review: Create Table using migrations
1) Create migration file
php artisan make:migration create_{name}_table
2) Code your table schema
3) To generata table, run: php artisan migrate
22. DB Config: Preparing database
• Create DB via phpmyadmin, e.g: “workshop”
• Config .env file
DB_HOST=localhost:8889
DB_DATABASE=workshop
DB_USERNAME=root
DB_PASSWORD=root
23. DB Config: Create migration for Quotes
php artisan make:migration create_quotes_table
Schema::create('quotes', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('content');
$table->string('author');
$table->timestamps();
});
24. DB Config: Create migration for Likes
php artisan make:migration create_likes_table
Schema::create('likes', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('quote_id');
$table->timestamps();
});
25. DB Config: Create Table Users
We don’t need to do anything,
Because Laravel have made users migration files (?)
2014_10_12_000000_create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
26. Ready to create table
php artisan migrate
Will generate table to database based on our
migration files just made
27. Review: Create Table using migrations
1) Create migration file
php artisan make:migration create_{name}_table
2) Code your table schema
3) To generata table, run: php artisan migrate
28. Your first awesome Larevel app:
Inspire (Quote sharing platform)
Features:
- Authentication (Register, Login, Logout)
- Create, Update and Delete Quote
- Quote Timeline (Display quote from all users)
- Like Quote
30. Create Login, Logout and Register
using “Laravel Magic”
php artisan make:auth
Will generate: view, controller and route for register,
login and logout
35. General Steps
2) Create controller
php artisan make:controller YourNewController
1) Define new feature route in routes.php
4) If needed, create model
php artisan make:model NewModelName
3) Create view using blade in resources/views
36. Define new feature routing
Route::get('/quote/timeline', 'QuoteController@timeline');
Route::post('/quote/save', 'QuoteController@store');
Route::get('/quote/edit/{id}', 'QuoteController@edit');
Route::post('/quote/update/{id}', 'QuoteController@update');
Open routes.php in App/Http/routes.php
Add this following code into routes.php
52. Your first awesome Larevel app:
Inspire (Quote sharing platform)
Features:
- Authentication (Register, Login, Logout)
- CRUD (Create, Retrieve, Update and Delete)
Quote
- Quote Timeline (Display quote from all users)
- Like Quote
53. General Steps
3) Create controller for handling Like request
php artisan make:controller LikeController
1) Define new route in routes.php
2) Create Like Model
php artisan make:model Like
4) We’d already made view for Like at prev step.
54. Define new feature routing
Route::get('/like/{quote_id}', ’LikeController@like');
Route::get('/unlike/{quote_id}', ’LikeController@unlike');
Open routes.php from App/Http/routes.php
Add this following code into routes.php