Thứ Tư, 14 tháng 9, 2016

#Part3 laravel 5 Blog Tutorial : Restful Controllers & Routing System


Create Blog Apps in Laravel 5.3 - To continue or CRUD / create blog apps in laravel, this lesson will discuss about Restful Controllers & Routing System in Blog project.

at the previews lessons, we has create database and connect it form laravel project, if you still confused, just read #Part2 laravel 5 Blog Tutorial : Database & Migration.

Restful Controllers & Routing System
To create new Controllers in our Laravel Project, we use 'Artisan Command' :

php artisan make:controller BlogController --resource

--resource syntax mean, we will create a controller (BlogController.php) with fully configuration/function like the Index functions, Store function, Create function, Show function, Edit function, and more.

This is default our Controller

Restful Controllers & Routing System

BlogController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class BlogController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function index()
    {
        // 
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return IlluminateHttpResponse
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpResponse
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function destroy($id)
    {
        //
    }
}

Next, create new routes, we has discuss about routes, please read for more detail Routing Basics in Laravel.

Web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

// we will ad new route into middleware group

Route::group(['middleware' => ['web']], function() {
  Route::resource('blog','BlogController');  
});

Video Tutorial Restful Controllers & Routing System



See you next Lessons...

Thứ Ba, 13 tháng 9, 2016

#Part2 laravel 5 Blog Tutorial : Database & Migration


Create Blog Apps in Laravel 5 - make simple blog using laravel 5.3 at this lessons will teach us about working with database and crate a migration in Laravel project.

that tutorial was published on previews lessons, pleas read :
  1. How to Connect Database in laravel 5.3
  2. Database Migration & Schema in Laravel 5.3

In this lessons, i assume you must see of the part1 before follow this tutorial, read Introductions to CRUD Operations in laravel 5.3 Part 1

Create Blog using laravel 5.3

Create Database

First, we will need to create a Database (i use MySQL database) in your server. So just create your own database. you can see this tutorial how to make an MySQL database?

Create Laravel Project

with your Terminal (CMD in windows), following this "Artisan CLI" command to create new project in laravel 5.3 :

composer create-project --prefer-dist laravel/laravel web

Intructions :

  1. we will create Laravel project using Composer
  2. web is your project name

Connect with Database

Next, we will create connection with our database, hasbeen posted on How to Connect Database in laravel 5.3

in your .ENV file, modife your connection variable, and configure it with yours.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_blog
DB_USERNAME=root
DB_PASSWORD=

Database Migration

Next, we need to create tables and columns in our database, using Migration in Laravel we will create a table or a columns with very easy, read Database Migration & Schema in Laravel 5.3

laravel 5 Blog Tutorial : Database & Migration

Create migration following by this command :

php artisan make:migration create_blog_table

After success, your migration file will be strored on database\migrations\2016_09_13_113838_crate_blog_table.php

Add some function following by this source code

<?php

use Illuminate\Support\Facades\Schema;
use Illuminat\eDatabase\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CrateBlogTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blog_post', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->string('description');
        $table->timestamps();
      });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('blog_post');
    }
}

Next, execute our migration scheme following by this command :

php artisan migrate

Now, you have a database "laravel_blog", with table name "blog_post" and some column name like, id, title,description, and time stamp in your database.


Video tutorial #Part2 laravel 5 Blog Tutorial : Database & Migration


Next lesson, we will try to show data from database and create a model in laravel 5.3

see you next lessons ...

Thứ Hai, 12 tháng 9, 2016

Laravel 5 Tutorial : CRUD Operations in laravel 5.3 Part 1


Laravel 5.3 Crud Example - How to make simple CRUD operations in Laravel 5.3 Apps? This Lessons will teach you about basics to make a blog apps using Laravel 5.3 and using simple basic of the CRUD (Create,Read,Update,Delete) Operations. This lessons, will be devided for 13 of the part, and updated everyday.

Previews Lessons, we have learn about How to Send mail using SMTP Gmail in Laravel and How to upload a file in Laravel 5.3

Create Simple Blog using Laravel 5.3

 What we have learned in this chapter? (updated)
  1. Intro to the basic of CRUD in Laravel 5.3
  2. Database Configuration and Migration
  3. Restful Controllers & Routing System
  4. Create Eloquent Model and Display the Data
  5. Insert data Operations query and Validation
  6. Create single Pages
  7. Update Data Into Databases
  8. Delete Data From Databases
  9. Pagination Eloquent
  10. Adding Bootstrap Theme

CRUD Operations in laravel 5.3
 That all is our Part to make a simple blog using Laravel 5.3, just follow or subscribe us to get updated new post everyday for free.

UPDATED :
New laravel 5.3 CRUD tutorial available here : Laravel 5 Crud Tutorial using Ajax & Bootstrap Template in Laravel 5.3

Video Tutorial Laravel 5 Ajax Crud


Video Tutorial Laravel 5 Crud with Vue.Js


Video Tutorial Laravel 5 HOW TO BUILD BLOG



See you Next Lessons..

Chủ Nhật, 11 tháng 9, 2016

C# & VB.NET Context Menu Right Click Copy, Cut, Paste Functions


C# .NET for beginners : How to add Context Menu Right Click with Copy, Cut, and Paste Functions in a TextBox or RichTextBox using C# and VB.NET?

Create Context Menu Right in C#

Add Copy, Cut, Paste Function

        void CutAction(object sender, EventArgs e) {
            richTextBox1.Cut();
        }

        void CopyAction(object sender, EventArgs e) {
            Clipboard.SetData(DataFormats.Rtf, richTextBox1.SelectedRtf);
        }

        void PasteAction(object sender, EventArgs e) {
            if (Clipboard.ContainsText(TextDataFormat.Rtf)) {
                richTextBox1.SelectedRtf = Clipboard.GetData(DataFormats.Rtf).ToString();
            }
            richTextBox1.Text = Clipboard.GetText();
        }

Next Add this source code on Event of a TextBox or RichTextBox

        private void richTextBox2_MouseDown(object sender, MouseEventArgs e) {
            if (e.Button == MouseButtons.Right) {
                ContextMenu contextMenu = new System.Windows.Forms.ContextMenu();
                MenuItem menuItem = new MenuItem("Cut");
                menuItem.Click += new EventHandler(CutAction);
                contextMenu.MenuItems.Add(menuItem);
                menuItem = new MenuItem("Copy");
                menuItem.Click += new EventHandler(CopyAction);
                contextMenu.MenuItems.Add(menuItem);
                menuItem = new MenuItem("Paste");
                menuItem.Click += new EventHandler(PasteAction);
                contextMenu.MenuItems.Add(menuItem);
                richTextBox1.ContextMenu = contextMenu;
            }
        }

Create context Menu Right in VB.NET

Add ContextMenuStrip component to your form, then add some items to this ContextMenuStrip like "Copy","CUT" and "Paste".

C# & VB.NET Context Menu Right Click Copy, Cut, Paste Functions

next add this source code :

Private Sub CutToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles CutToolStripMenuItem.Click
   RichTextBox1.Cut()
End Sub

Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles CopyToolStripMenuItem.Click
   RichTextBox1.Copy()
End Sub

Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles PasteToolStripMenuItem.Click
   RichTextBox1.Paste()
End Sub

See you next lessons ....

Thứ Bảy, 10 tháng 9, 2016

Laravel 5 Tutorial : How to Send Email using Gmail SMTP in laravel 5.3


Laravel 5.3 tutorial step by step - Laravel 5.3 can handle email functions, that we can send email using costum SMTP like smtp.gmail.com, Laravel uses free feature-rich library "SwiftMailer" to send emails.

At the previews lessons about Laravel 5.3 we has learned How to Create File Upload in laravel 5.3 and How to use Validation in Laravel 5.3, just learn it before try this one.

Send Email using Gmail SMTP in laravel 5.3

now, this lessons we will create simple apps that we can send email using smtp gmail.com, by following this syntax:

Mail::send(['text'=>'text.view'], $data, $callback);

First, we need to configurate our gmail account to Laravel project, that is on ".ENV" file, costum and configure with your gmail account :

How to Send Email using Gmail SMTP in laravel 5.3

.env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail@gmail.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls

Next, we need to clear our cache and restar Laravel Server by following this command :

Clear cache

php artisan config:cache

Next, we will create new controller to send email with Laravel by following this command :

Create new Controller

php artisan make:controller MailController

next, we will create three function in MailController.php
MailController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

// we will use Mail namespace
use Mail;

class MailController extends Controller
{
    // first, we create function for send Basics email
    public function basic_email(){
        $data=['name'=>'Harison matondang'];
        Mail::send(['text'=>'mail'], $data, function($message){
            $message->to('harisonmatondang@gmail.com','Harison Matondang')->subject('Send Mail from Laravel with Basics Email');
            $message->from('nabilaauliaputri29@gmail.com','Nabila');
        });
        echo 'Basics Email was sent!';
    }

    //create new function to send HTML email
    public function html_email(){
      $data=['name'=>'Harison matondang'];
      Mail::send(['text'=>'mail'], $data, function($message){
          $message->to('harisonmatondang@gmail.com','Harison Matondang')->subject('Send Mail from Laravel with HTML Email');
          $message->from('nabilaauliaputri29@gmail.com','Nabila');
      });
      echo 'HTML Email was sent!';
    }

    //create new function to send mail with attachment Mail
      public function attachment_email(){
        $data=['name'=>'Harison matondang'];
        Mail::send(['text'=>'mail'], $data, function($message){
            $message->to('harisonmatondang@gmail.com','Harison Matondang')->subject('Send Mail from Laravel with HTML Email');
            // add attach here
            // i have a image file on Laravel project
            $message->attach('C:serverhtdocshckrcompublicuploadsharison.jpg');
            $message->attach('C:serverhtdocshckrcompublicuploadssector-code.jpg');
            $message->from('nabilaauliaputri29@gmail.com','Nabila');
        });
        echo 'HTML Email was sent!';
      }
}

Next, create new view, that folder stored on resources/views and rename it with "mail.blade.php"

mail.blade.php

Hallo, {{ $name }}
i send a mail

Next create new routes

web.php

Route::get('/basicemail', 'MailController@basic_email');
Route::get('/htmlemail', 'MailController@html_email');
Route::get('/attachemail', 'MailController@attachment_email');

After finished, try to access your project with browser by following this URL :

http://localhost:8080/basicemail
http://localhost:8080/htmlemail
http://localhost:8080/attachemail

If you got some error like about Security by your gmail account, just setting and Allow less secure applications, by follwing this URL https://myaccount.google.com/security#activity and you will solved your problem.

Video tutorial Send Email with laravel



See you Next Lessons ...

Thứ Năm, 8 tháng 9, 2016

Laravel 5 Tutorial : How to Create File Upload in laravel 5.3


Laravel 5.3 File Uploading - To upload a file (image) in laravel 5.3 is so easy, we just need to create a controller, FileUpload Controller. at the previews Lessons, we have learn about Validation please read How to use Validation in Laravel 5.3 and about Sessions How to use Method HTTP Session in laravel 5.3.

Create File Upload in laravel 5.3

First, we need to create new Controller, please create FileuploadingController using Artisan CLI following by this command

php artisan make:controller FileuploadingController

Your controller will stored on app\Http\Controllers\FileuploadingController.php, Now Create function in the FileuploadingController.php

How to Create File Upload in laravel 5.3

FileuploadingController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class FileuploadingController extends Controller
{
    // create function for our upload page
    public function index(){
      return view('uploadfile');
    }
    // create new function for show uploaded page
    public function showfileupload(Request $request){
      $file = $request -> file('image');
      // show the file name
      echo 'File Name : '.$file->getClientOriginalName();
      echo '<br>';

      // show file extensions
      echo 'File Extensions : '.$file->getClientOriginalExtension();
      echo '<br>';

      // show file path
      echo 'File Path : '.$file->getRealPath();
      echo '<br>';

      // show file size
      echo 'File Size : '.$file->getSize();
      echo '<br>';

      // show file mime type
      echo 'File Mime Type : '.$file->getMimeType();
      echo '<br>';

      // move uploaded File
      $destinationPath = 'uploads';
      $file->move($destinationPath,$file->getClientOriginalName());
    }
}

Next, we need to create new Views and rename it with uploadfile.blade.php that save on resources\views\uploadfile.blade.php

uploadfile.blade.php

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Upload File</title>
  </head>
  <body>

    <?php
      echo Form::open(['url'=>'/uploadfile','files'=>'true']);
      echo 'Please Select a File to Upload ';
      echo '<br>';
      echo Form::file('image');
      echo '<br>';
      echo Form::submit('Upload File');
      echo '<br>';
      echo Form::close();
     ?>

  </body>
</html>

Next, add new routes, that Routes file stored on routes\web.php

web.php

Route::get('/uploadfile', 'FileuploadingController@index');
Route::post('/uploadfile', 'FileuploadingController@showfileupload');

After all finished, try to access our upload file project using your browser by following this command

http://localhost:8080/uploadfile

Video tutorial Create File Upload in laravel 5.3



See you next Lessons

Laravel 5 Tutorial : How to use Validation in Laravel 5.3


Laravel 5.3 - Validation, Validation in laravel 5.3 or at the all applications is the most important aspect while designing of them. It validates the incoming data. By default, base controller class uses a Validates Requests trait which provides a convenient method to validate incoming HTTP requests with a variety of powerful validation rules.

At the last Lessons, we have learn about Forms & HTML Class in laravel 5.3 and localization for Multiple languages in laravel 5.3

How to use Validation in Laravel 5.3

In your Laravel 5.3 project, create new Controller using Artisan CLI following this command

php artisan make:controller ValidationController

your new controller ValidationController has created and stored on app\Http\Controllers\Validation.php

add some function in our ValidationController.php

ValidationController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class ValidationController extends Controller
{
    // create new function to show the form login as a our index
    public function ShowForm(){
      return view('loginex');
    }
    // create function for our Validation
    public function ValidateForm(Request $request){
      print_r($request->all());
      $this->validate($request,[
          'username'=>'required|max:10',
          'password'=>'required'
      ]);
    }
}

Now, create new views to show our Login form, that stored on resources\views, at the preview Lessons, we have learn about Authentication Login & Registration Form + Bootstrap in laravel 5.3.

How to use Validation in Laravel 5.3

loginex.blade.php

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Validate Login</title>
  </head>
  <body>

    @if (count($errors) > 0)
      <div class="error">
        <ul>
          @foreach($errors->all() as $error)
            <li>{{ $error }}</li>
          @endforeach
        </ul>
      </div>
    @endif

    <?php
      echo Form::open(['url'=>'/validation']);
     ?>
     <table border="1">
       <tr>
         <td>
           Login
         </td>
       </tr>
       <tr>
         <td>
           username
         </td>
         <td>
           <?php echo Form::text('username'); ?>
         </td>
       </tr>
       <tr>
         <td>
           Password
         </td>
         <td>
           <?php echo Form::password('password'); ?>
         </td>
       </tr>
       <tr>
         <td>
           Password
         </td>
         <td>
           <?php echo Form::submit('login'); ?>
         </td>
       </tr>
     </table>
     <?php echo Form::close(); ?>
  </body>
</html>

Next, create new routes that stored on \routes\web.php

web.php

Route::get('/validation', 'ValidationController@ShowForm');
Route::post('/validation', 'ValidationController@ValidateForm');

Next, try to access our validation on your browser following this command

http://localhost:8080/validation

Video Tutorial How to use Validation in Laravel 5.3



See you next Lessions ...