I have two tables queries
and query_feedback_types
, the query table has one foreign key as query_feedback_type_id
, I have created two models for respective tables as Query.php
and QueryFeedbackType.php
these are both inside my App\Admin
folder.
So my problem is that when I try to make an Eloquent relationship between these two tables and returning all data from Queries table with the help of model Query and then I want to have data of query_feedback_types table also, but I am unable to access it via $row->queryFeedbackType->query
, this is giving me an error as
"Cannot make static method Illuminate\Database\Eloquent\Model::query() non static in class App\Admin\QueryFeedbackType"
I have already created a similar relationship but the table name in the database was very simple for it , faqs and categories with the foreign key in faqs as category_id.
and that relationship worked perfectly
Model Query.php
namespace App\Admin;
use DB;
use Illuminate\Database\Eloquent\Model;
class Query extends Model
{
public function queryFeedbackType()
{
return $this->belongsTo('App\Admin\QueryFeedbackType');
}
protected $fillable=
['name','email_id','mobile_no','query_feedback_type_id','remark'];
}
Model QueryFeedbackType
<?php
namespace App\Admin;
use DB;
use Illuminate\Database\Eloquent\Model;
class QueryFeedbackType extends Model
{
public function query()
{
return $this->hasMany('App\Admin\Query');
}
}
Controller QueryController.php
use DB;
use validator;
use File;
use App\Http\Controllers\Admin\Resize_Image;
use Helper;
class QueryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$data['page'] = 'View Feedback/Query';
$data['template'] = 'admin/query/view';
$data['results'] = Query::orderBy('id', 'desc')->get();
return view('admin/includes/page', compact('data'));
}
}
my coding page
<?php if ($data['results']){
$i=1;
foreach ($data['results'] as $row) {
?>
<tr>
{{$row->query_feedback_type}}
<td><center><?php echo $row->name; ?></center></td>
<td><center><?php echo $row->queryFeedbackType->id ?> //getting error in this line
Error:
"Cannot make static method Illuminate\Database\Eloquent\Model::query() non static in class App\Admin\QueryFeedbackType"
Please explain to me the mistake I am doing here.