Estou tentando fazer minha primeira API com Laravel/PHP.
Estou tentando testar com o php artisan tinker:
var_dump( App\Company::all() );
Porém, recebo:
Illuminate/Database/QueryException with message 'SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from
companies
)'
app/Company.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
protected $fillable = ['name', 'email', 'website', 'logo', 'password'];
protected $hidden = ['password'];
protected $dates = ['deleted_at'];
public function jobs(){
return $this->hasMany('App\Job');
}
}
Meu arquivo .env:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:KMNas/3ovm6UNhdsafaNHbajwXwo0SrvyLEQ51A/0waE=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=""
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
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=
PUSHER_APP_CLUSTER=mt1
Não entendi exatamente o que ele não conseguiu encontrar. Minha classe? Meu bd? Minha tabela?
@Edit:
Minhas migrations:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 100);
$table->string('email', 60);
$table->string('website');
$table->string('logo');
$table->string('password', 64);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('companies');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->longText('description');
$table->string('local');
$table->enum('remote', ['yes', 'no']);
$table->integer('type');
$table->integer('company_id')->unsigned();
$table->foreign('company_id')
->references('id');
->on('companies')
->onDelete('cascade');
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}