SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table (Laravel 5)

My regular query is like this :


SELECT a.nationality_id, a.nationality_name, b.province_name, c.city_name
FROM tb_general_nationality a
JOIN tb_search_province b ON a.nationality_id = b.country_id
JOIN tb_search_city c ON b.province_id = c.province_id
WHERE b.country_id = 50

I change the query to laravel query like this :

Service :


public function listCity($param=null)
{
$city = City::with('province','country')->where('tb_search_province.country_id',$param)->get();
echo json_encode($city);
}

Model :

City Model :


namespace AppModelsCity;

use IlluminateDatabaseEloquentModel;

class City extends Model {

protected $connection = 'pgsql';

protected $table = 'tb_search_city';

public function province()
{
return $this->belongsTo('AppModelsProvinceProvince','province_id','province_id');
}

}

Country Model :


namespace AppModelsCountry;

use IlluminateDatabaseEloquentModel;

class Country extends Model {

protected $connection = 'pgsql';

protected $table = 'tb_general_nationality';

}

Province Model :


namespace AppModelsProvince;

use IlluminateDatabaseEloquentModel;

class Province extends Model {

protected $connection = 'pgsql';

protected $table = 'tb_search_province';

public function country()
{
return $this->belongsTo('AppModelsCountryCountry','nationality_id','country_id');
}

}

But, my laravel query not working. There exist error. The error is like this :


SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "tb_search_province"
LINE 1: select * from "tb_search_city" where "tb_search_province"."c...
^ (SQL: select * from "tb_search_city" where "tb_search_province"."country_id" = 50)

My Table is like this:


tb_search_city (city_id, province_id, city_name)
tb_search_province (province_id, country_id, province_name)
tb_general_nationality (nationality_id, nationality_name)

How to change the regular query to laravel query correctly?

Thank you very much

from Newest questions tagged laravel-5 – Stack Overflow http://ift.tt/1UxMKNz
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.