我想在名为" property"
的另一个模型中调用listcity函数/model/Crawler.php
class Crawler extends Model {
public function listcity($statename)
{
$ins="exec Prc_Lst_CityMaster @CountryName = 'India', @StateName = '".$statename."'";
return DB::select($ins);
}
}
/model/Property.php
use App\Models\Crawler,
class Property extends Model {
public function __construct(Crawler $Crawler)
{
$this->Crawler = $Crawler;
}
public function propertyDetails($id)
{
$this->Crawler->listcity($id);
}
}
但是我收到了错误
ErrorException(E_NOTICE) 试图获得非对象的属性
答案 0 :(得分:1)
您应该使用关系而不是将模型注入另一个模型。但是如果你想这样做,你需要手动完成,而不是通过构造函数:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imagesArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = uploadDocCollectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! UploadDocsImagesCollectionViewCell
cell.imageView.image = imagesArray[indexPath.item]
return cell
}
答案 1 :(得分:0)
您需要在模型中添加Crawler
的属性。
public $Crawler;
public function __construct(Crawler $Crawler)
{
$this->Crawler = $Crawler;
}