在我的应用程序中,用户可以向其他用户提醒事件邀请.为此,我需要传递事件的ID和要邀请的用户.
在我的路线文件中,我有:
Route::get('events/{id}/remind', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);
Run Code Online (Sandbox Code Playgroud)
在我看来,我有:
{!!link_to_route('remindHelper', 'Remind User', $parameters = array($eventid = $event->id, $userid = $invitee->id) )!!}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我有:
public function remindHelper($eventid, $userid)
{
$event = Events::findOrFail($eventid);
$user = User::findOrFail($userid);
$invitees = $this->user->friendsOfMine;
$invited = $event->helpers;
$groups = $this->user->groupOwner()->get();
return view('events.invite_groups', compact('event', 'invitees', 'invited', 'groups'));
}
Run Code Online (Sandbox Code Playgroud)
但是,当我点击该路线时,我收到以下错误:
Missing argument 2 for App\Http\Controllers\EventsController::remindHelper()
Run Code Online (Sandbox Code Playgroud)
我确定我的视图中存在格式错误,但我无法对其进行诊断.有没有更有效的方法将多个参数传递给控制器?
在我的Laravel应用程序中,我经常需要使用Guzzle将数据POST到API.
API用户使用承载令牌进行身份验证,并请求和接受原始json.为了测试,我使用Postman访问了API,一切都运行得非常好.
邮差标题:
Accept:application/json
Authorization:Bearer [token]
Content-Type:application/json
Run Code Online (Sandbox Code Playgroud)
和邮递员身体:
{
"request1" : "123456789",
"request2" : "2468",
"request3" : "987654321",
"name" : "John Doe"
}
Run Code Online (Sandbox Code Playgroud)
邮递员返回200,并返回JSON对象作为响应.
现在,当我尝试使用Guzzle时,我得到一个200状态代码,但没有返回JSON对象.这是我的Guzzle实现:
public function getClient($token)
{
return new Client([
'base_uri' => env('API_HOST'),
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json'
]);
}
$post = $client->request('POST', '/path/to/api', [
'json' => [
'request1' => 123456789,
'request2' => 2468,
'request3' => 987654321,
'name' => 'John Doe',
]
]);
Run Code Online (Sandbox Code Playgroud)
使用Guzzle发布JSON有一些技巧吗?如果没有,有没有办法调试引擎盖下发生的事情?
在我的生活中,我不能理解Postman POST和Guzzle POST之间的区别.
我正在创建一个小的Timer Vue组件。用户需要能够启动和停止该计时器。到目前为止,这是我的组件:
<template>
<div>
<a class="u-link-white" href="#" @click="toggleTimer">
{{ time }}
</a>
</div>
</template>
<script>
export default {
props: ['order'],
data() {
return {
time: this.order.time_to_complete,
isRunning: false,
}
},
methods: {
toggleTimer() {
var interval = setInterval(this.incrementTime, 1000);
if (this.isRunning) {
//debugger
clearInterval(interval);
console.log('timer stops');
} else {
console.log('timer starts');
}
this.isRunning = (this.isRunning ? false : true);
},
incrementTime() {
this.time = parseInt(this.time) + 1;
},
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我切换isRunning变量以确定计时器是否正在运行。第一次单击(播放)时,计时器开始计时并成功递增。
但是,在第二次单击(暂停)时,isRunning变量将切换回关闭状态,但clearInterval(this.incrementTime)没有清除间隔并暂停计时器。当我插入该调试器并clearInterval(interval) …
在我的Rails应用程序中,我正在构建一个功能,允许用户使用Javascript代码段从其他网站上的应用程序嵌入数据.
我的Javascript片段向我的rails应用程序中的路由发出GET请求,该路由返回原始JSON.当片段和JSON共享同一个域时,一切运行良好,但是当我将片段嵌入到另一个站点时,我遇到了CORS问题.
使用我在这里找到的解决方案,我已经开始为CORS配置我的Rails应用程序.
在我的application_controller.rb:
before_filter :add_allow_credentials_headers
def add_allow_credentials_headers
response.headers['Access-Control-Allow-Origin'] = request.headers['Origin'] || '*'
response.headers['Access-Control-Allow-Credentials'] = 'true'
end
def options
head :status => 200, :'Access-Control-Allow-Headers' => 'accept, content-type'
end
Run Code Online (Sandbox Code Playgroud)
在我的routes.rb:
get 'embed_json' => 'application#options', :via => [:options]
Run Code Online (Sandbox Code Playgroud)
但是,当我在浏览器中点击上述路径时,应用程序不再返回JSON对象 - 只是一个空白屏幕.
关于如何在单个Rails路由上最好地处理CORS似乎存在许多相互矛盾的方法.有没有"Rails方式"来处理这个要求?
我正在使用格式如下的 GeoJSON 数据集:
{
"type": "Feature",
"properties": {
"startcong": "109",
"district": "7",
"statename": "Pennsylvania",
"member": {
"112": {
"21168": {
"party": "Republican",
"name": "Meehan, Pat",
"district": "7"
}
},
"109": {
"15447": {
"party": "Republican",
"name": "Weldon, Curt", "district": "7"}
},
"110": {
"20744": {
"party": "Democrat",
"name": "Sestak, Joe",
"district": "7"
}
},
"111": {
"20744": {
"party": "Democrat",
"name": "Sestak, Joe",
"district": "7"
}
}
},
"endcong":
"112",
"id": "042109112007"
}
}
Run Code Online (Sandbox Code Playgroud)
我正在努力解决如何访问这些嵌套对象的问题。例如,我可以使用feature.properties.member[112][21168]来访问该party属性。然而:
我会定期遇到需要使用Spatie的Browsershot捕获极高网页的场景.但是,当我这样做时,结果屏幕截图每16,384像素重复一次.(你可以在这里看到一个重复的例子:https://github.com/GoogleChrome/puppeteer/issues/1576)
这是Puppeteer的已知限制(此处记录).目前推荐的解决方法似乎是采用了几个屏幕截图,并使用clip()以16,384px的增量来抵消屏幕截图.您可以在此处查看使用Node.js的此方法的示例.
现在,在客户端,这种方法似乎运行得很好,但在Browsershot库的上下文中,这并没有真正帮助我们.据我所知,在PHP中获取页面高度没有可行的方法; 任何人都可以想到服务器端的任何潜在的解决方法来破解极长的截图吗?
我知道这不是库的预期用途,并且在一天结束时,它甚至不是图书馆的限制,但我认为无论如何我都会把它扔出去.
在我的 Laravel 应用程序中,衬衫有多种尺寸:
public function sizes()
{
return $this->hasMany(\App\Size::class, 'size_id');
}
Run Code Online (Sandbox Code Playgroud)
尺码有一个属性name,可以是 SM、MD、LG、XL、XXL 等。
我想sortBy()在雄辩的关系中添加 a,以便尺寸始终按从 SM 到 XXL 的顺序出现。
是否可以编写基于字符串值的排序?我只是根据一个值是否大于另一个值来编写它们,但这显然不适用于这里。