Reputation: 1146
I'm very confused, i try to find what's wrong but i don't find it..
My migration file:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateClientProjectTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('client_project', function(Blueprint $table)
{
$table->increments('id');
$table->integer('client_id');
$table->integer('project_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('client_project');
}
}
First of all, i check table is created, and it is.
Then, the route
who calls to the controller
is this: (is prefixed by admin
)
Route::post('projectsclients/postUpload', ['uses' => 'AdminController@storeProjectsClients', 'as' => 'admin.projectsclients.store']);
The functions looks like here:
$client_project = new Client_Project();
$client_project->client_id = DB::table('clients')->orderby('id','DESC')->take(1)->get();
$client_project->project_id = DB::table('projects')->orderby('id','DESC')->take(1)->get();
$client_project->save();
And the error:
Base table or view not found: 1146 Table 'web.client__projects' doesn't exist
The problem is my table is client_project
not client__projects
.
Where i have to fix this?
Thanks a lot, any help will be appreciated.
Upvotes: 0
Views: 209
Reputation: 3409
You are not following Laravel naming conventions. To solve this particular issue yo can explicitly define tabe name. In class Client_Projects
definition add this:
protected $table = 'client_project';
But to learn about naming conventions I suggest reading related section in documents here https://laravel.com/docs/5.4/eloquent#eloquent-model-conventions
Upvotes: 2
Reputation: 3666
You shouldn't be breaking up class name with _
for one. It should be named ClientProject
. Generally if there is a problem with the table you would edit the modal and add a
ClientProject.php
public $table = 'client_project';
Upvotes: 2