Search code examples
laravellaravel-5composer-phplaravel-5.4laravel-artisan

Php artisan migrate - unexpected 'string' (T_STRING)


When I run php artisan migrate to make the tables for my databases in Laravel I get the following error:

 [Symfony\Component\Debug\Exception\FatalThrowableError]
 Parse error: syntax error, unexpected 'string' (T_STRING), expecting variable (T_VARIABLE)

I think that this error is quite useless since it doesn't tell me in what file, and what place something is wrong (and that makes it very hard to understand what's going on).

The migration seems to fail with the first migration since it didn't generate a single table in my database.

This is the migration (User -> generated with php artisan make:auth):

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('avatar');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('users');
    }
}

It is just the default migration with one new line. I can't find out what's wrong with it. I already tried composer dump-autoload and composer clearcache but nothing works.

I hope somebody knows a solution.

EDIT: it appears to happen before the first migration runs. Is there a file where something might be wrong?

You can read my Laravel.log file here: https://pastebin.com/1PrDwady


Solution

  • It looks from your stack trace as though you may have accidentally edited the function definition for string() at this point: C:\xampp\htdocs\urenlijstje\vendor\laravel\framework\src\Illuminate\Database\Schema\Blueprint.php:473

    One of the variable names is likely missing the $ indicating to the PHP parser that it is indeed a variable.

    Here is the line of code as it should be in Laravel 5.4.

    In situations like this where the framework won't boot, I've often traced back issues to inadvertent edits like this. Since your vendor directory is not in source control (or shouldn't be at least!), another option is to rm -rf vendor && composer install and see if that fixes your issue.