我正在使用: 1. Laravel 5 2. https://github.com/MarkRedeman/Imgur-Laravel
我的控制器:
public function store()
{
$input = Request::all();
$upload = new Upload($input);
$upload->save();
$upload_id = $upload->id;
$path = $this->resizeAndSaveTempImage($upload->raw_image_url);
$done = $this->uploadToImgur($path);
dd($done);
}
public function resizeAndSaveTempImage($image_url)
{
$img = Image::make($image_url)->insert('http://i.imgur.com/Ned0D1ub.jpg', 'top', 130, 330);
$tmp_name = 'final-output-' . microtime(true) . '.jpg';
$path = 'tmp/' . $tmp_name;
$img->save($path);
return $path;
}
public function uploadToImgur($image_path)
{
$imageData = array(
'image' => $image_path,
'type' => 'file',
'name' => 'Lipsum',
'title' => 'Lorem Ipsum',
'description' => 'Lorem Ipsum Dolor Sit Amet'
);
$basic = Imgur::api('image')->upload($imageData);
return $basic;
}
死亡和转储的结果:
Basic {#236 ▼
-data: array:20 [▼
"id" => "KWIhRsS"
"title" => "Lorem Ipsum"
"description" => "Lorem Ipsum Dolor Sit Amet"
"datetime" => 1431732751
"type" => "image/jpeg"
"animated" => false
"width" => 640
"height" => 640
"size" => 95601
"views" => 0
"bandwidth" => 0
"vote" => null
"favorite" => false
"nsfw" => null
"section" => null
"account_url" => null
"account_id" => 0
"deletehash" => "z8M21wNHdsFOBhJ"
"name" => "Lipsum"
"link" => "http://i.imgur.com/KWIhRsS.jpg"
]
-success: true
-status: 200
}
但是如果我尝试访问链接
dd($done->data['link']);
它给了我这个错误:
Cannot access private property Imgur\Api\Model\Basic::$data
如何从响应对象访问链接?
答案 0 :(得分:0)
在此处调查代码后:
https://github.com/Adyg/php-imgur-api-client/blob/master/lib/Imgur/Api/Model/Basic.php
我使用的包扩展了,返回对象的$ data属性存在一个getter。
$done->getData()