Search code examples
phpmysqllaravelcomposer-phplaravel-artisan

Something wrong with my Laravel


there's defenitely something wrong with my Laravel.

I have the Laravel 5.4 installed. I have installed Composer on my windows globally. I have php artisan working, but I'm getting errors everywhere:


php artisan tinker

When I type in php artisan make:model Brand it says Model created succesfully. Awesome, right? When I type in php artisan tinker and App/Brand::all() next, it says Class 'Brand' not found.

While I have Brand.php inside my app folder:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Brand extends Model
{
    //
}

By the way, I'm following this series at laracast.


mySQL

I can't run the mysql command, though I have manually installed mySQL on my windows (globally as well).

It says

'mysql' is not recognized as an internal or external command,
operable program or batch file.

migrate

php artisan migrate gives me this error:

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key
length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key
length is 767 bytes

Besides this php artisan migrate is working very well, it creates two tables for me: migrations and users. I thought that was because I have two files in my \database\migrations folder. But...

When I say php artisan make:migration create_brands_table --create=brands, it creates a file inside this folder indeed. Like it should. I add a few lines inside the up() function so it looks like this:

Schema::table('brands', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->text('description');
    $table->timestamps();
});

But it does not create a table.

Please note that I did edit my .env file to make a proper database connection, otherwise php artisan migrate would not work on the other two tables I did create with the php artsian migrate command.

It only gives a alreadt exists error. I tried migrate:rollback and migrate:refresh as well. I tried doing this after the composer dump-autoload command, but it came with the same result.


I'm lost in the dark here, I am obviously new to Laravel, but some friends of mine who are familiar with Laravel have never experienced the problems I have.


I have tried to reinstall and create a new project and all... guess what: same results.


Solution

  • You got namespaces wrong, use backslash: App\Brand

    To create a table use Schema::create and not Schema::table

    The mysql part is not Laravel's concern and should not be in this question. Anyway you should check your environment PATH variable.