Sabtu, Juli 23

How to install Laravel 5 with Xampp (Windows)

 sumur : codementor.io

Requirements

  • PHP >= 5.5.9
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension

Install Xampp

First of all, we need Xampp, so we can download it from the official page: Download Xampp

Composer

After you've downloaded and installed Xampp, we need to install Composer.
Composer is a PHP package manager that is integrated with Laravel Framework. In Windows we can install it easy going to the official page and download the installer.
Composer Download page
After install it, we can open a Windows terminal and write composer for execute the command:

Xampp Virtual Host

We will configure a Virtual Host in Xampp for a Laravel project, and in this example, we want to configure the domain laravel.dev for our project.
We need to edit httpd-vhosts.conf that is located in C:\xampp\apache\conf\extra\httpd-vhosts.conf and add following lines at the end of the file:
# VirtualHost for LARAVEL.DEV

<VirtualHost laravel.dev:80>
    DocumentRoot "C:\xampp\htdocs\laravel\public"
    ServerAdmin laravel.dev
    <Directory "C:\xampp\htdocs\laravel">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
After this, our apache is listening to laravel.dev connections, but we have to configure our hosts file that allows to redirect laravel.dev to the localhost that is located in C:\Windows\System32\drivers\etc

IMPORTANT!: To edit this file, maybe we should give access, click properties and allow your user to modify this file. Edit hosts file adding our localhost for laravel.dev:
# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost

127.0.0.1    laravel.dev
Save the file and we are ready to install laravel.

Install Laravel Framework

We are prepared to install and configure a Laravel Framework. First of all, we have to navigate to htdocs folder to install it and run this following command:
composer create-project laravel/laravel laravel "5.1.*"
Will start the installation of the Framework:

When it finishes, it will create following directory schema:

Finally, start our apache and MySql from Xampp control panel:

Success!
Navigate to laravel.dev and Laravel it's installed!



Alternative Distinct dan Group By

Sumur : Distinct Alternative

You want to select distinct values from a column in a table. No problem. You use DISTINCT or GROUP BY in your query. But did you know that there is a third way to suppress duplicates? For example:

Both
select distinct department_id  
from employees
and
select department_id  
from employees
group by department_id
return
DEPARTMENT_ID          
---------------------- 
100                    
30                     

90                     
20                     
70                     
110                    
50                     
80                     
40                     
60                     
10                     

12 rows selected
Boring. Nothing new here.

But wait a minute, here is what I learnt today, another way to return distinct department ids, using the function ROW_NUMBER:
select department_id
from (
  select department_id,
         row_number( ) over 
           (partition by department_id 
            order by department_id) rownumber
    from employees
         ) t
   where rownumber = 1
 returns
DEPARTMENT_ID          
---------------------- 
10                     
20                     
30                     
40                     
50                     
60                     
70                     
80                     
90                     
100                    
110                    


12 rows selected
It’s the same output as the first two queries, except that it is ordered differently.
To be honest, I will continue using DISTINCT or GROUP BY for such requirements, however, it does not hurt to know that there are alternatives.