AssetController.php第21行中的ErrorException:尝试获取非对象的属性

时间:2018-05-28 23:51:45

标签: laravel laravel-5.2

我有这个代码源,我正在尝试在我的一个项目中使用它,它与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)执行此操作之外我没有办法填写该表

0 个答案:

没有答案