所以我得到一個陌生人的錯誤。laravel雄辯改變了我的查詢表名...?咦?
QueryException in Connection.php line 651: SQLSTATE[42S02]:
Base table or view not found: 1146 La table
'aba.progresses' n'existe pas
(SQL: select * from `progresses` where
`user_id` = 1 and `task_type` = Match Pictures limit 1)
事情是,'進展'不是我的表。這是真的。但是,從我所知道的情況來看,我的代碼中沒有「進步」。
從索引方法調用:檢查取得進展變量
public function index()
{
$tasktype = 'Match Pictures';
$session = \App\Sessions::where('user_id', '=', \Auth::user()->id)
->where('task_type', '=', $tasktype)
->where('status', '=', 'started')->first();
//if no session has been started.
//then start the session and redirect
if (empty($session))
{
//get Progress info
$getProgress = \App\Progress::where('user_id', '=', \Auth::user()->id)
->where('task_type', '=', $tasktype)->first();
if (empty($getProgress))
{
$newProgress = new \App\Progress;
$newProgress->user_id = \Auth::user()->id;
$newProgress->task_type = $tasktype;
$newProgress->stimuli_set = 5;
$newProgress->save();
$addSession = new \App\Session;
$addSession->user_id = \Auth::user()->id;
$addSession->task_type = $tasktype;
$addSession->stimuli_set = $newProgress->stimuli_set;
$addSession->number_of_trials = $newProgress->stimuli_set;
$addSession->save();
//Gather Data
$data['status'] = 'first';
$data['message'] = "This is your first time playing Match Pictures!";
//send to view with task start button and introduction
return view('task.matchpictures.intro');
}
else
{
//add Session
$addSession = new \App\Session;
$addSession->user_id = \Auth::user()->id;
$addSession->task_type = $tasktype;
$addSession->stimuli_set = $getProgress->stimuli_set;
$addSession->number_of_trials = $getProgress->stimuli_set;
$addSession->save();
$data['status'] = "not first";
$data['message'] = "This is your first time playing Match Pictures!";
//send to view with task start button and introduction
return view('task.matchpictures.intro');
}
}
else
{
//Make Sure that the Session has Finished.
$trialCount = \App\Trials::where('session_id', '=', $session->session_id)
->count();
if ($trialCount >= $session->number_of_trials)
{
//end session by update session row (status = done)
// then send to page for summary
$session->status = 'done';
$session->save();
//send view to a Task Summary Page
return view('task.matchpictures.summary');
}
else
{
//A session has started but is not done. Proceed:
redirect('/task/matching/active');
}
}
return "There was an error. Go back to the main page.";
}
現在我的進步模式是空的,但拼寫正確。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Progress extends Model
{
//
}
然後,我們有我們的遷移...這很好。
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProgressTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('progress', function (Blueprint $table) {
$table->unsignedInteger('user_id');
$table->string('task_type');
$table->integer('stimuli_set')->default('5');
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('progress');
}
}
我真的不確定在哪裏可能會受到影響。這是怎麼發生的?!哈哈。
謝謝
看起來雄辯被翻譯您的類名成多。在ORM中並不罕見。 – Kenney