Parse error: syntax error, unexpected '\'

Published 4 months ago by dagyoe

When I create pivot table via migration and only error.

<?php

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

class App\ extends Migration         <--------Error line-----<
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
Best Answer (As Selected By dagyoe)
shez1983

He told you the name of the file doesnt match the class name.. i m not sure what else you are expecting him to say.. :s

name your class CreatePostTagPivotTable and your problems will go away..

basically your laravel must be doing some magic to look for the class name based on the file name even though file name is some ugly date_create_post_tag_table..

wilk_randall

Get rid of the \ on App. Also, typically people don't name their migrations "App". It's usually something more descriptive like "CreateUsersTable".

dagyoe

If I get rid \.It's another error Class 'CreatePostTagPivotTable' not found in vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php: 418

wilk_randall

Well, I can't really help you with what little you have provided. My guess is your migration file name does not match up with the class name.

dagyoe

so now I don't know what do you think

wilk_randall

I told you what I think. Could you show the entire file? And also the name of the migration file as well because the naming of them is important.

dagyoe

2018_02_17_204738_create_post_tag_pivot_table.php

<?php

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

class App\ extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('post_tag', function (Blueprint $table) {
            $table->integer('post_id')->unsigned()->index();
            $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
            $table->integer('tag_id')->unsigned()->index();
            $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
            $table->primary(['post_id', 'tag_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('post_tag');
    }
}
shez1983

He told you the name of the file doesnt match the class name.. i m not sure what else you are expecting him to say.. :s

name your class CreatePostTagPivotTable and your problems will go away..

basically your laravel must be doing some magic to look for the class name based on the file name even though file name is some ugly date_create_post_tag_table..

wilk_randall

It looks like what I thought originally. Try renaming the class to CreatePostTagPivotTable and it should work.

dagyoe

@shez1983 thank you :) I'm trying to programing first time

dagyoe

@wilk_randall thanks too men ;)

Please sign in or create an account to participate in this conversation.