Skip to content
Advertisement

Bash : Syntax Error Near Unexpected Token `’table_name’`

I’m getting started learning Laravel 5 in Ubuntu 15.04. So, I’m done creating my database but when I’m trying to insert data using Terminal, I’ve got some error that says

bash : syntax error near unexpected token `'table_name'`

Here’s my terminal inputs in my laravel app directory

DB::table('table_name')->insert(['title' => 'My First Title', 'create_at' => new DateTime, 'updated_at' => new DateTime]);

It’s just an simple queries on adding datas inside my database but I can’t get through this thing. Is there any one who can help me? I’ve checked the other question like these but in my condition, I think its different and I couldn’t find some possible solutions base on their questions.

Advertisement

Answer

What you have there is not a bash command. Consequently, when entered at a bash prompt, it generates an error message:

$ DB::table('table_name')->insert(['title' => 'My First Title', 'create_at' => new DateTime, 'updated_at' => new DateTime]);
bash: syntax error near unexpected token `'table_name''

In the above, bash believes that you are trying to define a function called DB::table. A function definition would typically look like: DB::table() { cmd1; cmd2; }. In this form, however, bash does not expect to find a token between the open and close parens. Therefore, it generates an error message as shown above.

To execute that command, an interpreter that understands Laravel is needed. Fortunately, there is just such an interpreter included with Laravel and it is called Artisan. You can read more about it here.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement