我想知道Laravel是否有任何助手来修改集合。我需要做的是使用paginate()进行查询,然后检查登录的用户ID是否与发送者或接收者匹配,然后根据该ID将新值添加到输出中:
$userId = Auth::guard('api')->user()->user_id;
$allMessages = Conversation::join('users as sender', 'conversations.sender_id', '=', 'sender.user_id')
->join('users as reciver', 'conversations.recipient_id', '=', 'reciver.user_id')
->where('sender_id',$userId)->orWhere('recipient_id',$userId)
->orderBy('last_updated', 'desc')
->select('subject','sender_id','recipient_id','sender_unread','recipient_unread','last_updated','reciver.username as receivername','sender.username as sendername')
->paginate(20);
Run Code Online (Sandbox Code Playgroud)
现在我想做类似的事情:
if ( $allMessages->sender_id == $userId ) {
//add new value to output
newField = $allMessages->sendername
} else {
//add new value to output
newField = $allMessages->receivername
}
Run Code Online (Sandbox Code Playgroud)
然后发送添加了新值的数据
return response()->json(['messages' => $allMessages],200);
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我想知道当我使用标签栏时如何更改标签中标题的字体和大小.
我查看了文档,我无法找到有关标题字体和大小的任何内容 - 来源
我正在使用选项卡栏控制器,我想知道是否有一种方法可以检查单击哪个选项卡?
如果用户单击“帐户”选项卡而未登录,我想重定向到全屏模式登录屏幕而不是帐户VC。
我正在使用 CGPoint 值来设置动画开始的位置。
transition.startingPoint = startButton.center
Run Code Online (Sandbox Code Playgroud)
如果我这样做print(startButton.center),输出将是:(292.0, 22.0)
我现在想要做的是编辑 Y 位置的值,以便动画在屏幕上的位置稍低,我可以将新值传递给 transition.startingPoint = newVal
我想知道图像干预中的stream()函数做什么吗?http://image.intervention.io/api/stream
现在,我将像这样将图像上传到亚马逊S3:
public function uploadLargeAndMainImages($file,$adId)
{
$s3 = Storage::disk('s3');
$extension = $file->guessExtension();
$filename = uniqid() . '.' . $extension;
//Create and resize images
$image = Image::make($file)->resize(null, 600, function ($constraint) {
$constraint->aspectRatio();
});
$image->encode($extension);
$imageLarge = Image::make($file)->resize(null, 800, function ($constraint) {
$constraint->aspectRatio();
});
$imageLarge->encode($extension);
// upload image to S3
$s3->put("images/{$adId}/main/" . $filename, (string) $image, 'public');
$s3->put("images/{$adId}/large/" . $filename, (string) $imageLarge, 'public');
// make image entry to DB
$file = File::create([
'a_f_id' => $adId,
'file_name' => $filename,
]);
}
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚如何在swift3中删除此警告:
调用'responseMessagesArray'的结果未使用
这是我的代码的样子:
fileprivate class func getMessagesAtPath(_ path: String, tokenKey: String, completionHandler: @escaping (MyMessagesWrapper?, NSError?) -> Void) {
let credentialData = ":\(tokenKey)".data(using: String.Encoding.utf8)!
let base64Credentials = credentialData.base64EncodedString(options: [])
let headers = ["Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Basic \(base64Credentials)"]
Alamofire.request(path, headers: headers)
.responseMessagesArray { response in
if let error = response.result.error
{
completionHandler(nil, error as NSError?)
return
}
completionHandler(response.result.value, nil)
}
}
class func getMyMessages(_ completionHandler: @escaping (MyMessagesWrapper?, NSError?) -> Void) {
getMessagesAtPath(MyMessages.endpointForMyMessages(),tokenKey: MyMessages.getTokenKey(),completionHandler: completionHandler)
}
extension Alamofire.DataRequest {
func responseMessagesArray(_ …Run Code Online (Sandbox Code Playgroud)