Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

2014-02-09

Level Up - Webmaster: Setting Up Your First Laravel Website Or App

(For webmasters, a continuation on my last post Level Up - Webmaster: Installing Laravel and Composer on Bluehost.)

This walkthrough contains all the instructions I would have needed on one page, rather than looking through twenty different pages. This is a blunt how-to for connecting to a database with Laravel and displaying information. At the end are links for more specific and advanced info.

The following has explicit instructions and commands for a shared hosting provider like Bluehost, but the instructions should be the roughly the same for other providers and setups. I suggest to follow the steps explicitly the first time through, then run through it a second time with your specific project's names.

0. This simple "tutorial" assumes that you already know a little bit about Laravel and have possibly read my first install and setup walkthrough.

Setup the database:
1. Create a database on your server with a user and password.
2. From your root project folder, edit app/config/database.php to match your new database credentials.
3. In your root project directory, run php-cli artisan migrate:make create_users_table
4. You should now have the file that looks something like: app/database/migrations/2014_02_09_195357_create_users_table.php. Edit the up() and down() function to look like:
    public function up()
    {
        Schema::create('users', function($table)
        {
            $table->increments('id');
            $table->string('email')->unique();
            $table->string('name');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::drop('users');
    }
5. Now, back in the project root dir, run: php-cli artisan migrate
6. At this time, your tables in the database will be automatically created. Add some data manually so that we can test that retrieving data works.

Create a view:
7. Create a route (subdirectory pointer) in app/routes.php by adding the following code:
    Route::get('users', function()
    {
        $users = User::all();

        return View::make('users')->with('users', $users);
    });
8. Create two new views in app/views. Call the first one layout.blade.php and add this code:
   
       
           

Laravel Quickstart



            @yield('content')
        
    
Create the second view, called users.blade.php:
    @extends('layout')

    @section('content')
        @foreach($users as $user)
            {{ $user->name }}
        @endforeach
    @stop
9. Go to your doman.com/users and you should have all the user names from the database displayed on the page.


Note:
- If the php-cli command doesn't work for you, then try just php


More info:

2013-03-20

Connect to Remote Database

Today, I tried three popular programs of connecting to a remote database. In this post I will compare the pros and cons of each of the methods. My motivation was to find a method to share access to a single database and not be able to see or access any other databases on my server. [My server (Bluehost), doesn't allow access to phpMyAdmin without going through CPanel.]

First, the summary:
 - I would use HeidiSQL for speed, responsiveness, and ease of use.
 - I would use phpMyAdmin if I wasn't on my own computer with HeidiSQL installed.
 - I wouldn't use MySQL Workbench at this time nor recommend for beginners.


HeidiSQL:
 - Very quick to learn
 - Shows exactly what I need to get started. (See lower-right window in the HeidiSQL screenshot below)
 - Very clean method of organizing everything.
 - Con: Must be downloaded first in order to work.

http://www.heidisql.com/


PhpMyAdmin:
 - Available with just about every server; on CPanel.
 - When setting up a remote login for team members, it took just 5 minutes. All I had to do was download the files from the site and upload it to my server. Then anybody can access the URL and see the login page.
 - Con: Seems a little show at times.

http://www.phpmyadmin.net/home_page/


MySQL Workbench:
 - Harder to begin with.
 - Couldn't easily show table data.
 - When first starting, user is presented with a flood of information which was a turn off for me.
 - The interface may seem a little cleaner at first, but that comes at a cost of not being able to find functionalities quickly and easily. In order to efficiently use this MySQL Workbench, user needs to spend time looking through all the menus and right-clicking everything. My first thought about the program was that it was missing basic functionalities like being able to show data from the tables. But, I eventually found the function.
 - The screenshot below show this program using null to describe the data in the first row. Having null values in each cell is different that not having any rows of data...

http://www.mysql.com/products/workbench/



I'd love to hear your comments, reviews, and comparisons of these and other programs.

~ Simply Advanced ~

Disclaimer: I only tested each of these programs for about 5-10 minutes before drawing a conclusion. So, this can be used as a judgement for learning curve.