I can’t open project in Laravel

Asked

Viewed 672 times

0

I have a project in Laravel that after I formatted the computer I can no longer open it. The following steps have been performed:

  1. Installation of XAMPP and change the default path to the project folder.
  2. Installation of Composer and subsequently update thereof.
  3. Creation of the project database on Mysql.
  4. When rotating the command PHP artisan migrate and artisan serve appears the following error:

Migrate e Serve

  1. On the web page appears like this: inserir a descrição da imagem aqui

  2. The file . env is configured this way. This key was there the same way before the machine was formatted. Running php Artisan key:generate gives error and cannot generate new key.

Code

APP_ENV=local
APP_NAME=SGP
APP_KEY=base64:eEtD6lSEsQGE/aDDVHgVHXKLpmaj1XzhMTtiFhOukqQ=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://sgp.patrimonio
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sgpmehos_bd
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

The Migration that is showing error is 2017_10_22_134724_create_permissions_table.php and the codes inserted in it are:

<?php

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

class CreatePermissionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('permissions', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nome', 50);
            $table->string('label', 200);
            $table->timestamps();
        });

        Schema::create('permission_role', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('permission_id')->unsigned();
            $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
            $table->integer('role_id')->unsigned();
            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('permissions');
        Schema::dropIfExists('permission_role');
    }
}

Model: Permission.php

<?php

namespace App\Models\Acesso;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
    public function scopeSearch($query, $pesquisa){
        return $query->where('nome', 'like','%' .$pesquisa. '%' );
    }

    public function roles()
    {
        return $this->belongsToMany(\App\Models\Acesso\Role::class);
    }
}

Can you help me?

  • o . env ta configured correctly? if yes tries to run this command php Artisan migrate:refresh

  • edited to ask to leave better explained. As for the refresh command did not work. It says that the database does not exist.

  • vc created the sgpmehos_bd database in mysql?

  • Yes, I created the database with that name.

  • created another mysql user? if it is an updated mysql certainly the root user can not access the database at least I had this problem here

  • Do the following then, go to the mysql database to check if there is any table in the sgpmehos_db database and delete all, then try again!

  • @Bulfaitelo created and still continues with the same error.

  • @Lodi no table in the bank. :(

  • The error is that there is no db.Permissions table

  • Jeez, let’s analyze you have a Migration with that name correct?

  • Rotate this command here php artisan migrate:refresh --seed and tell me the result of it.

  • Hi @Lodi, yes I have.

  • @Bulfaitelo circled the remote and made the same mistake, my friend.

  • @Lodi will post the structure of this Migration in the question.

  • puts the model too, there must be a model, Permissions, looks for protected $table = "Permissions"; if you haven’t added that line and tests again.

  • I put the model Permission code.

  • @Lucasaugustocoelholopes is the following in Migration having the model will not interfere in the process as I understood, your problem is when running php Artisan migrate, as very well mentioned here, check carefully the following items: 1. Database sgpmehos_bd created? 2. Is your . env configured correctly? 3. Try running php Artisan migrate:Fresh command, do this only if it is in homologation, do not execute this command in production.

Show 12 more comments

1 answer

0


Following for what you reported:

Delete the database;

Restart the XAMP;

Create the database in hand again (Make sure the name has been typed correctly);

After that run the command "php Artisan dump-autoload"

Then: php Artisan migrate --force

Browser other questions tagged

You are not signed in. Login or sign up in order to post.