Query in model is not recognized only Facades error 1054/1064 [closed]

1 day ago 1
ARTICLE AD BOX

When performing this query, the Forum model is not recognized, but other models are, and the query only works using facades. Why does this happen?

use App\Models\Forum;

use Illuminate\Support\Facades\DB;

Model: Forum.php

<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Forum extends MainModel { protected $table = 'forums'; protected $fillable = [ 'forum_name', 'forum_tittle', 'forum_description', 'user_id' ]; } <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Models\Setting; class MainModel extends Model { public function __construct() { } }

Controller : The query on the table is not recognized (Syntax error or access violation: 1064).

$forum = Forum::select('forums.forum_name,forums.forum_tittle,forums.forum_description') ->where('id', 1) ->first();

enter image description here This method doesn't work either and displays another error (Column not found: 1054).

$forum = Forum::select('forum_name,forum_tittle,forum_description') ->where('id', 1) ->first();

enter image description here

This way it is recognized.

$forum = DB::table('forums') ->where('id', 1) ->first();

enter image description here

Read Entire Article