Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Laravel 4 Basics Laravel and Databases Migrations & Schema Builder

How to change db table from todo_list to todo_list2?

when I create new a table $php artisan migrate:make create_todo_lists_table2 --create=todo_lists2

and go to TodolistController.php change ->with("")

public function index()
    {
        $todo_lists = TodoList::all();
        return View::make('todos.index')->with('todo_lists2', $todo_lists);
    }

index.blade.php

@extends('layouts.main')
@section('content')
    <h1>All Todo Lists</h1>
    <ul>
        @foreach ($todo_lists2 as $list)
            <li>{{{ $list->name }}}</li>
        @endforeach
    </ul>
@stop

I checked MYSQL workbench it created todo_lists2 table put two name on two rows "your christmas" and "my christmas".

and the other table is todo_lists the two rows "your name" and "my name".

go to http://laracast2.dev:8000/ the show is "your name" and "my name" why it does not show as "your christmas" and my christmas" for todo_list2?

I do not understand what is going on with interacting database. anyone please help me what did I am wrong or missing.

You need to change table name in your TodoList model or add it if it doesn't exist

protected $table = todo_lists2;

2 Answers

The comment above is absolutely bang on.

Here:

<?php

public function index()
    {
        $todo_lists = TodoList::all();
        return View::make('todos.index')->with('todo_lists2', $todo_lists);
    }

you're only changing the name of the variable that's available to you in the view.

In your view (index.blade.html) you will be able to access $todo_lists2, but this will still be the value from $todo_lists in your controller.

In your model TodoList, you set where the information is coming from (which table the model is associated with).

Change

<?php
protected $table = todo_lists;

to:

<?php
protected $table = todo_lists2;

or just insert this into your model (probably somewhere near the top, but this doesn't matter).

Hope this helps!

Hi Tom,

You have a small typo (index.blade.html) :)

That's what I said isn't it?!

Sorry i don't know what you exactly.

Anyway, blade files should be a php file not html :)