我正试图在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 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)
不确定该怎么做.不管它是否是一条路线都不在乎,但需要以某种方式获得该动作名称.
我正在尝试使用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并且从未遇到过问题.所以不确定问题的来源.
我想提出一个请求:
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)
但没有运气.如何指定我需要返回的字段?
所以我最近推出了一个jQuery插件,人们正在下载它,但我想弄清楚我怎么知道它在哪里被使用.我能想到的唯一方法是尝试以某种方式搜索.js或.css文件,也许是文件夹名称.
无论如何都要搜索这个?
我正在尝试使用随机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,但似乎无法得到它去.
尝试做一个简单的重定向:
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) 我对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实际上是什么呢?
这是否也意味着我要么必须将所有状态对象都更改为函数,要么在注销时使用某种重置方法。这似乎毫无意义,我在这里想念什么?
我正在尝试更改输入中的自动填充背景颜色。
在线接受的答案似乎是这样的:
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无法覆盖?
刚开始使用 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设置标头。
我需要麻烦设置它们吗?如果我不这样做,可能会出现什么情况或错误?
laravel ×4
laravel-5 ×3
javascript ×2
node.js ×2
php ×2
autocomplete ×1
content-type ×1
css ×1
eloquent ×1
express ×1
http-headers ×1
jquery ×1
laravel-4 ×1
nginx ×1
plugins ×1
redirect ×1
sails.js ×1
search ×1
vue-router ×1
vue.js ×1
vuejs2 ×1
vuex ×1
vuex-modules ×1
waterline ×1
webkit ×1