小编Rob*_*Rob的帖子

使用Laravel Socialite和API?

我正试图在api上使用Laravel Socialite包.我尝试将代码传递给我的api来获取用户,但它一直给我一个错误:

Fatal error: Call to a member function pull() on null
Run Code Online (Sandbox Code Playgroud)

由于我正在通过API执行请求,因此我采取以下步骤.

向api发送请求以获取代码:

Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()
Run Code Online (Sandbox Code Playgroud)

然后使用上面提取的url发出请求,该url使用code参数重定向.

将代码发送到api并获取用户:

$fb_user = Socialite::with('facebook')->user();
Run Code Online (Sandbox Code Playgroud)

这是它崩溃的地方.我不知道为什么.

我之前使用过这个包,当我只有一个重新加载页面的应用程序时,它工作正常.但当我将它发送到api(在不同的域上)时,它会崩溃.我在想如何生成代码存在一些问题.有没有什么办法解决这一问题?

php laravel laravel-socialite

10
推荐指数
2
解决办法
6326
查看次数

如何在Laravel中获取中间件路由

目前,我可以通过将其注入我想要使用它的方法中来获取控制器中的路径.

<?php namespace App\Http\Controllers;

use Illuminate\Routing\Route;

class HomeController extends Controller
{
    public function getIndex(Route $route)
    {
        echo $route->getActionName();
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我试图在中间件中执行类似的操作,但无法实现.

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Routing\Route;
use Illuminate\Contracts\Routing\Middleware;

class SetView implements Middleware {

    protected $route;

    public function __construct(Route $route)
    {
        $this->route = $route;
    }

    public function handle($request, Closure $next)
    {
        echo $this->route->getActionName();

        return $next($request);
    }
}
Run Code Online (Sandbox Code Playgroud)

得到一个错误.

Unresolvable dependency resolving [Parameter #0 [ <required> $methods ]] in class Illuminate\Routing\Route
Run Code Online (Sandbox Code Playgroud)

不确定该怎么做.不管它是否是一条路线都不在乎,但需要以某种方式获得该动作名称.

php laravel laravel-5

9
推荐指数
2
解决办法
2万
查看次数

Laravel Jenssegers MongoDb关系不起作用?

我正在尝试使用Laravel/Jenssegers MongoDB为我的应用设置一些简单的收藏

我有两个型号:

class Item {

    public function favorites()
    {
       return $this->hasMany('App\Models\User', 'favorites');
    }
}

class User {

    public function favorites()
    {
       return $this->hasMany('App\Models\Item', 'favorites');
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,项目可以包含许多用户,并且用户可以拥有许多项目或"收藏夹".

当我尝试运行一个简单的查询,如:

Item::with('favorites')->get();
Run Code Online (Sandbox Code Playgroud)

收藏夹的关系是一个空数组.

该favorites表很简单,只有三列:

_id, item_id, user_id
Run Code Online (Sandbox Code Playgroud)

我也尝试过embedsMany没有运气:

return $this->embedsMany('App\Models\User', 'favorites');
Run Code Online (Sandbox Code Playgroud)

我也尝试过各种参数组合.

return $this->embedsMany('App\Models\User', 'favorites', 'building_id', 'user_id');
return $this->embedsMany('App\Models\User', 'favorites', 'user_id', 'building_id');
return $this->hasMany('App\Models\User', 'favorites', 'building_id', 'user_id');
return $this->hasMany('App\Models\User', 'favorites', 'user_id', 'building_id');
Run Code Online (Sandbox Code Playgroud)

使用时产生奇怪的结果:

return $this->hasMany('App\Models\User', 'favorites', 'building_id', 'user_id');
Run Code Online (Sandbox Code Playgroud)

只有在这种情况下它才会返回所有用户,即使收藏夹只有一条记录.

尝试使用调试getQueryLog只是给我一个空数组.

print_r(\DB::connection('mongodb')->getQueryLog());
Run Code Online (Sandbox Code Playgroud)

我已经完成了这项工作mysql并且从未遇到过问题.所以不确定问题的来源.

laravel laravel-5 jenssegers-mongodb

9
推荐指数
1
解决办法
1130
查看次数

在Node.js/Waterline中指定返回的字段?

我想提出一个请求:

User.find().exec(function(){});
Run Code Online (Sandbox Code Playgroud)

我知道我可以toJSON在模型中使用但是我不喜欢这种方法,因为有时我需要不同的参数.例如,如果是登录用户,我将返回他们的电子邮件和其他参数.然而,如果请求相同的数据由不同的用户做出,则它将不包括电子邮件和较小的参数子集.

我也尝试过使用:

User.find({}, {username:1}) ...
User.find({}, {fields: {username:1}});
Run Code Online (Sandbox Code Playgroud)

但没有运气.如何指定我需要返回的字段?

node.js express sails.js waterline

8
推荐指数
3
解决办法
5441
查看次数

如何在谷歌搜索JavaScript文件?

所以我最近推出了一个jQuery插件,人们正在下载它,但我想弄清楚我怎么知道它在哪里被使用.我能想到的唯一方法是尝试以某种方式搜索.js或.css文件,也许是文件夹名称.

无论如何都要搜索这个?

javascript search jquery plugins

6
推荐指数
1
解决办法
404
查看次数

Laravel Bulk UPDATE

我正在尝试使用随机slugs为每条记录更新一个包含slug值的表.

$vouchers = Voucher->get(); // assume 10K for example

foreach ($vouchers as $voucher) {
    $q .= "UPDATE vouchers set slug = '" . Str::random(32) . "' WHERE id = " . $voucher->id . ";";
}

DB::statement($q);
Run Code Online (Sandbox Code Playgroud)

大约有200万条记录,因此我需要将其作为批量执行.单独记录这样做太长了.我似乎无法找到批量运行它们的方法,比如以10K或者其他类似的组.

尝试了一堆的变化->update()和DB::statement,但似乎无法得到它去.

laravel eloquent laravel-4 laravel-5

6
推荐指数
2
解决办法
9298
查看次数

Nginx重定向规则无效

尝试做一个简单的重定向:

rewrite https://url.example.com(.*) https://example.com/plugins/url permanent;
Run Code Online (Sandbox Code Playgroud)

任何时候url.example.com被击中,我都希望它重定向到该特定路径。

编辑:

将尝试更好地解释这一点,因为我正尝试从另一个域重定向到特定域。

server {
    server_name example.com plugin.example.com;
    root /home/www/example.com/public;
}
Run Code Online (Sandbox Code Playgroud)

我看到了location用于重定向的内容,例如:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}
Run Code Online (Sandbox Code Playgroud)

但不确定在我的情况下如何使用它,即更改plugin.example.com为example.com/plugin。

例如:

http://plugin.example.com
https://plugin.example.com
https://plugin.example.com/blah
https://plugin.example.com/blah/more
Run Code Online (Sandbox Code Playgroud)

所有这些都应重定向到:

https://example.com/plugin
Run Code Online (Sandbox Code Playgroud)

redirect nginx url-rewriting

6
推荐指数
1
解决办法
64
查看次数

Vuex unregisterModule是做什么的?

我对unregisterModule实际操作有些困惑。

如果我们有这样的模块:

{
    state: {
        page: 1
    }
}
Run Code Online (Sandbox Code Playgroud)

然后动态取消/注册:

beforeCreate() {        
    this.$store.registerModule('items', store);
},

beforeDestroy() {
    this.$store.unregisterModule('items');
},
Run Code Online (Sandbox Code Playgroud)

如果我们更改page导航方式(触发unregister),则向后导航。

似乎状态仍然存在?我认为unregister完全杀死了该模块以及所有数据,状态等?

我可以使状态成为这样的函数:

{
    state() {
        return {
            page: 1
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,那它仍然不会改变问题,那unregisterModule实际上是什么呢?

这是否也意味着我要么必须将所有状态对象都更改为函数,要么在注销时使用某种重置方法。这似乎毫无意义,我在这里想念什么?

vue.js vue-router vuex vuejs2 vuex-modules

6
推荐指数
1
解决办法
239
查看次数

谷歌浏览器自动填充背景颜色变化?

我正在尝试更改输入中的自动填充背景颜色。

在线接受的答案似乎是这样的:

删除 Chrome 自动完成的输入背景颜色?

input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active,
input:-internal-autofill-selected,
input:-internal-autofill-previewed {
    background-color: white !important;
    -webkit-box-shadow: 0 0 0 30px white inset !important;
}
Run Code Online (Sandbox Code Playgroud)

这似乎在一种情况下可以接受,即字段已经自动填充时。

这意味着我刷新了浏览器,并且这些字段已经预先填充了用户名/密码。

当我将鼠标悬停在或单击输入时,背景颜色会发生变化。但是,当我什么都不box-shadow做时没有效果,它仍然设置为默认的user agent stylesheet.

input:-internal-autofill-selected {
    background-color: rgb(232, 240, 254) !important;
    background-image: none !important;
    color: rgb(0, 0, 0) !important;
}
Run Code Online (Sandbox Code Playgroud)

我也尝试了一些随机属性但没有成功。

input:-internal-autofill,
input:-internal-autofill:hover, 
input:-internal-autofill:focus, 
input:-internal-autofill:active,
Run Code Online (Sandbox Code Playgroud)

Chrome 版本 77.0.3865.90(官方版本)(64 位)

根本不知道如何覆盖它。就像它被添加到 css 规则的底部一样,important无法覆盖?

css webkit google-chrome autocomplete

6
推荐指数
1
解决办法
4616
查看次数

是否有必要在 Node.js 中设置 Content-Type?

刚开始使用 Node.js,在看到几个例子后,我发现通常Content-Type在返回一些内容之前设置。

对于 HTML,通常是这样的:

res.writeHead(200, {'Content-Type': 'text/html'});
res.write(html);
res.end();
Run Code Online (Sandbox Code Playgroud)

对于图像:

res.writeHead(200, {'Content-Type': 'image/png'});
res.write(img, 'binary');
res.end();
Run Code Online (Sandbox Code Playgroud)

我阅读了.write()的文档,它说如果没有指定标题“它将切换到隐式标题模式并刷新隐式标题”

通过一些测试,我发现我可以像这样写一行:

res.end(html); // or
res.end(img);
Run Code Online (Sandbox Code Playgroud)

这两个工作正常。我还使用本地 Apache 服务器进行了测试,当我查看加载图像时设置的标头时,那里没有Content-Type设置标头。

我需要麻烦设置它们吗?如果我不这样做,可能会出现什么情况或错误?

javascript content-type http-headers node.js

5
推荐指数
1
解决办法
6284
查看次数