php - When going through Laracast Tutorials, the output I get doesn't match what they get. What am I doing wrong? -


i'm going through laracasts tutorials tinker not laracasts , won't i'm trying do

    psy shell v0.5.1 (php 5.5.12 ÔÇö cli) justin hileman >>> $article = app\article::create{['title' => 'new article', 'body' => 'new body', 'published_at' => carbon\carbon::now()]); php parse error: syntax error, unexpected '{' on line 1 >>> $article = app\article::create{['title' => 'new article', 'body' => 'new body', 'published_at' => carbon\carbon::now()]); php parse error: syntax error, unexpected '{' on line 1 >>> $name php error:  undefined variable: name on line 1 >>> $article = new app\article; => app\article {#655} >>> $article => app\article {#655} >>> new app\user; => app\user {#648} >>> $article = new app\article; => app\article {#651} >>> 

this it's displaying know wrong?

edit: new error won't let me continue

    $article->save();     illuminate\database\queryexception message 'sqlstate[hy000]: general error: 1 no such table: articles (sql: insert "articles" ("body", "published_at", "title", "updated_at", "created_at") v     alues (lorem ipsum, 2015-07-22 15:20:49, first article, 2015-07-22 15:27:15, 2015-07-22 15:27:15))' 

edit2: tried article find line , showed this

    psy shell v0.5.1 (php 5.5.12 ÔÇö cli) justin hileman >>> $article = new app\article; => app\article {#652} >>> $article - app\article::find(1); illuminate\database\queryexception message 'sqlstate[hy000]: general error: 1 no such table: articles (sql: select * "articles" "articles"."id" = 1 limit 1)' 

the contents of config/database.php file are:

<?php  return [  /* |-------------------------------------------------------------------------- | pdo fetch style |-------------------------------------------------------------------------- | | default, database results returned instances of php | stdclass object; however, may desire retrieve records in | array format simplicity. here can tweak fetch style. | */  'fetch' => pdo::fetch_class,  /* |-------------------------------------------------------------------------- | default database connection name |-------------------------------------------------------------------------- | | here may specify of database connections below wish | use default connection database work. of course | may use many connections @ once using database library. | */  'default' => 'sqlite',  /* |-------------------------------------------------------------------------- | database connections |-------------------------------------------------------------------------- | | here each of database connections setup application. | of course, examples of configuring each database platform | supported laravel shown below make development simple. | | | database work in laravel done through php pdo facilities | make sure have driver particular database of | choice installed on machine before begin development. | */  'connections' => [      'sqlite' => [         'driver'   => 'sqlite',         'database' => storage_path().'database.sqlite',         'prefix'   => '',     ],      'mysql' => [         'driver'    => 'mysql',         'host'      => env('db_host', 'localhost'),         'database'  => env('db_database', 'forge'),         'username'  => env('db_username', 'forge'),         'password'  => env('db_password', ''),         'charset'   => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix'    => '',         'strict'    => false,     ],      'pgsql' => [         'driver'   => 'pgsql',         'host'     => env('db_host', 'localhost'),         'database' => env('db_database', 'forge'),         'username' => env('db_username', 'forge'),         'password' => env('db_password', ''),         'charset'  => 'utf8',         'prefix'   => '',         'schema'   => 'public',     ],      'sqlsrv' => [         'driver'   => 'sqlsrv',         'host'     => env('db_host', 'localhost'),         'database' => env('db_database', 'forge'),         'username' => env('db_username', 'forge'),         'password' => env('db_password', ''),         'charset'  => 'utf8',         'prefix'   => '',     ],  ],  /* |-------------------------------------------------------------------------- | migration repository table |-------------------------------------------------------------------------- | | table keeps track of migrations have run | application. using information, can determine of | migrations on disk haven't been run in database. | */  'migrations' => 'migrations',  /* |-------------------------------------------------------------------------- | redis databases |-------------------------------------------------------------------------- | | redis open source, fast, , advanced key-value store | provides richer set of commands typical key-value systems | such apc or memcached. laravel makes easy dig right in. | */  'redis' => [      'cluster' => false,      'default' => [         'host'     => '127.0.0.1',         'port'     => 6379,         'database' => 0,     ],  ],  ]; 

i recreated error mentioned. problem lies within migration file. in both up() , down() methods should use

schema::create('articles' ...

and

schema::drop('articles' ...

respectively. if use 'article' instead, run described error. keep in mind table many articles, it's name 'articles', while model describes 1 article - that's why it's name 'article' - still reads/writes records from/to 'articles' table. hope helps.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -