I have searched for people who encountered this error but I still can't find the solution.
I have been getting the error:
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'material_tags.material_uuid' in 'field list' (SQL: select
tags
.*,material_tags
.material_uuid
aspivot_material_uuid
,material_tags
.tag_uuid
aspivot_tag_uuid
fromtags
inner joinmaterial_tags
ontags
.uuid
=material_tags
.tag_uuid
wherematerial_tags
.material_uuid
in (05a36470-d0a0-11e7-91b4-ff3d7d9f961a) andtags
.deleted_at
is null)"
in which if I have to view Material 05a36470-d0a0-11e7-91b4-ff3d7d9f961a it should look like this
When I try to run this code located on the controller:
public function show(Request $request, $id)
{
$material = Material::with('tags')->where(
'uuid',
$id
)->first();
where my Material Model has this:
public function tags()
{
return $this->belongsToMany('App\Models\Tag', 'material_tags');
}
So I have a Tags table where all the tags are stored, and a Materials table that has all the materials stored. and I have the Material_tags table to see what Materials have tags.
my create_materials_table at migration
public function up()
{
Schema::connection('materials')->create('materials', function (Blueprint $table) {
$table->uuid('uuid')
->primary();
$table->string('title');
$table->integer('viewing_time')
->default(15)
->comment('In seconds');
$table->text('description')
->nullable();
$table->uuid('organization_id')
->nullable();
$table->timestamps();
$table->softDeletes();
});
}
my create_tags_table migration
public function up()
{
Schema::connection('materials')->create('tags', function (Blueprint $table) {
$table->uuid('uuid')
->primary();
$table->string('name')
->unique();
$table->timestamps();
$table->softDeletes();
});
}
and my create_material_tags_table migration
public function up()
{
Schema::connection('materials')->create('material_tags', function (Blueprint $table) {
$table->uuid('uuid')
->primary();
$table->uuid('material_id');
$table->uuid('tag_id');
$table->timestamps();
$table->foreign('material_id')
->references('uuid')
->on('materials')
->onDelete('cascade');
$table->foreign('tag_id')
->references('uuid')
->on('tags')
->onDelete('cascade');
});
}