라이브러리
[PHP] TableSelect::__construct - TableSelect 생성자
TableSelect::__construct
TableSelect는 Laravel의 Eloquent ORM에서 제공하는 기능 중 하나로, 특정 테이블에 대한 쿼리를 생성하는 데 사용됩니다. TableSelect::__construct는 TableSelect 클래스의 생성자 함수로, 테이블 이름과 옵션을 전달받아 TableSelect 인스턴스를 생성합니다.
# 예제
#hostingforum.kr
php
use IlluminateDatabaseEloquentBuilder;
use IlluminateDatabaseEloquentModel;
use IlluminateSupportFacadesDB;
class User extends Model
{
protected $table = 'users';
public function scopeTableSelect($query)
{
return $query->select('id', 'name', 'email');
}
}
$table = (new User)->getTable();
$tableSelect = new TableSelect($table, ['id', 'name', 'email']);
// 테이블 이름과 컬럼 이름을 지정하여 TableSelect 인스턴스를 생성
echo $tableSelect->getTableName(); // users
echo $tableSelect->getColumns(); // [id, name, email]
// TableSelect 인스턴스를 사용하여 쿼리를 생성
$query = DB::table($tableSelect);
// 쿼리 결과를 가져옵니다.
$result = $query->get();
// 결과를 출력합니다.
foreach ($result as $row) {
echo $row->id . ', ' . $row->name . ', ' . $row->email . "
";
}
# 옵션
TableSelect::__construct에 전달할 수 있는 옵션은 다음과 같습니다.
* `table`: 테이블 이름을 지정합니다. 기본값은 `null`입니다.
* `columns`: 컬럼 이름을 지정합니다. 기본값은 `null`입니다.
# 예제 (옵션 사용)
#hostingforum.kr
php
$tableSelect = new TableSelect('users', ['id', 'name', 'email']);
// 테이블 이름과 컬럼 이름을 지정하여 TableSelect 인스턴스를 생성
echo $tableSelect->getTableName(); // users
echo $tableSelect->getColumns(); // [id, name, email]
# 참고
TableSelect는 Laravel의 Eloquent ORM에서 제공하는 기능 중 하나로, 특정 테이블에 대한 쿼리를 생성하는 데 사용됩니다. TableSelect::__construct는 TableSelect 클래스의 생성자 함수로, 테이블 이름과 옵션을 전달받아 TableSelect 인스턴스를 생성합니다. TableSelect 인스턴스를 사용하여 쿼리를 생성하고 결과를 가져올 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.