laravel - AssetController.php 第 21 行中的 ErrorException:试图获取非对象的属性
问题描述
我有这个代码源,我试图在我的一个项目中使用它,它与 laravel 5.2 一起使用。这是assetController中的函数:
namespace App\Http\Controllers;
use App\Setting;
use File;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AssetController extends Controller
{
/**
* List all image from image directory
*/
public function getAsset()
{
//Get Admin Images
$adminImages = array();
//get image file array
$images_dir = Setting::where('name', 'images_dir')->first();
$folderContentAdmin = File::files($images_dir->value);
//check the allowed file extension and make the allowed file array
$allowedExt = Setting::where('name', 'images_allowedExtensions')->first();
$temp = explode('|', $allowedExt->value);
foreach ($folderContentAdmin as $key => $item)
{
if( ! is_array($item))
{
//check the file extension
$ext = pathinfo($item, PATHINFO_EXTENSION);
//prep allowed extensions array
if (in_array($ext, $temp))
{
array_push($adminImages, $item);
}
}
}
//Get User Images
$userImages = array();
$userID = Auth::user()->id;
$images_uploadDir = Setting::where('name', 'images_uploadDir')->first();
if (is_dir( $images_uploadDir->value . "/" .$userID ))
{
$folderContentUser = File::files($images_uploadDir->value . "/" .$userID );
if ($folderContentUser)
{
foreach ($folderContentUser as $key => $item)
{
if ( ! is_array($item))
{
//check the file extension
$ext = pathinfo($item, PATHINFO_EXTENSION);
//prep allowed extensions array
//$temp = explode("|", $this->config->item('images_allowedExtensions'));
if (in_array($ext, $temp))
{
array_push($userImages, $item);
}
}
}
}
}
//var_dump($folderContent);
//var_dump($adminImages);
return view('assets/images', compact('adminImages', 'userImages'));
}
问题出在第 21 行:
//get image file array
$images_dir = Setting::where('name', 'images_dir')->first();
$folderContentAdmin = File::files($images_dir->value);
从我的研究中我发现原因是因为设置表是空的,这是真的。如果不是这种情况,请告诉我是否还有其他原因导致该问题我需要解决方案,因为除了从数据库本身(phpmyAdmin)之外,我没有办法填充该表
解决方案
推荐阅读
- google-bigquery - How to find out the PK & indexes on table/data-to-insights:ecommerce.web_analytics?
- angular - Collapsing items in dx-forms
- sinon - 就 Sinon spy 的最新通话参数进行断言
- .htaccess - 转发“maindomain”,但保持“maindomain/en/”等仍然有效
- python - 尽管根据 getchildren() 存在子元素,python lxml 无法识别子元素
- vb.net - 如何在 Dim NormalVectorRotationMatrix As New devDept.Geometry.Matrix 之后将元素添加到矩阵
- api - OneLogin API 凭据
- powershell - 使用凭据启动作业失败,错误用户名/密码不正确
- javascript - 如何将 Django 变量传递给 Vue 道具
- python-3.x - 如何在向 keras 中的神经网络提供输入的同时使用两个不同的生成器?