我在https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Output/Output.php他们使用的第40行看到了这段代码?int.
public function __construct(?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null)
{
$this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
$this->formatter = $formatter ?: new OutputFormatter();
$this->formatter->setDecorated($decorated);
}
Run Code Online (Sandbox Code Playgroud) Route::group(array('domain' => 'api.domain.com'), function()
{
Route::get('/','TwitterController@index');
Route::get('/gettweets','TwitterController@getTweets');
Route::get('/viewtweets','TwitterController@viewTweets');
Route::get('/viewvideos','TwitterController@viewVideos');
});
Run Code Online (Sandbox Code Playgroud)
这是我的routes.php
我正在呼叫这/gettweets条路线,但它说/gettweets服务器上找不到.使用godaddy linux共享.我只能打电话/请求.我怎样才能让laravel阅读这条路线.
我的简单查询显示此错误
DB::table('news')->join('categories', 'news.category_id', '=', 'categories.id')
->join('users', 'news.created_by', '=', 'users.id')
->select('news.*', 'categories.name as category_name','users.name as user_name','categories.bn_name','users.photo','news.photo as n_photo')
->where('status', 1)
->orderBy('news.id', 'desc')
->take(5)
->get();
Run Code Online (Sandbox Code Playgroud) 假设我从API获取了json以下的响应.
{
"owner": "Jane Doe",
"pets": [
{
"color": "white",
"type": "cat"
},
{
"color": "black",
"type": "dog"
}
]
}
Run Code Online (Sandbox Code Playgroud)
从下面的PHP代码我已经将json字符串转换为json对象.并显示宠物类型.
$jsonObject = json_decode($json);
foreach($jsonObject->pets as $pets){
echo 'Pet type:'.$pets->type.'</br>';
}
Run Code Online (Sandbox Code Playgroud)
但是在某些情况下,来自API的响应json采用以下格式
{
"owner": "John Doe",
"pets": {
"color": "white",
"type": "cat"
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,上面的php foreach迭代失败,下面的消息
*注意:试图获得非对象的属性*
我正在寻找一种简单的方法来实现这一点,因为我正在处理的实际json响应中有很多这样的事件.