小编Kha*_* Bz的帖子

((何处和何处)或(何处和何处))Laravel 5.2

我正在尝试创建((Where and Where)OR(Where and Where))经过大量搜索,我发现了这一点

    $sender = \App\User::where('username','=',$username)->firstOrFail();
    $receiver = Auth::user();
    $messages = \App\Message::Where(function($query)
                              {
                                  $query->where("sender",$sender->id)
                                        ->where("receiver",$receiver->id);
                              })
                              ->orWhere(function($query)
                              {
                                  $query->Where("sender",$receiver->id)
                                        ->Where("receiver",$sender->id);
                              })
                              ->get();
Run Code Online (Sandbox Code Playgroud)

但它告诉我$ sender$ receiver变量是未定义的,请帮忙,我正在尝试显示两个用户的消息,我还想我可以单独获取第一个(在哪里和哪里)然后得到第二个,然后我将合并它们.

php where-clause eloquent laravel-5.2

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

检索上个月的所有行(Laravel + Eloquent)

我正在尝试获取上个月的所有记录,到目前为止,我设法从上个月获取了所有记录,但是到目前为止,我不确定如何只获取上个月的记录

$revenueMonth = Callback::where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->sum('payment');
Run Code Online (Sandbox Code Playgroud)

php mysql laravel eloquent php-carbon

5
推荐指数
3
解决办法
8006
查看次数

覆盖静态变量

我有两个类(模型和用户),但我有一个问题所以我试图在一个简单的例子中解释它:

class person
{
    protected static $todo ="nothing";

    public function __construct(){}

    public function get_what_todo()
    {
        echo self::$todo;
    }
}

class student extends person
{
    protected static $todo ="studing";
}

$s = new student();
$s->get_what_todo(); // this will show the word (nothing)
                     //but I want to show the word (studing)
Run Code Online (Sandbox Code Playgroud)

请给我一个解决方案,但没有在学生班写任何功能我只想在那里做声明:)谢谢:)

php inheritance static-members

4
推荐指数
2
解决办法
3263
查看次数

在静态方法中从当前类创建对象 - PHP

我的模型类和其他类有一些问题,所以我做了这个简单的例子来解释我的问题:

class person{

  public static $a = "welcome";

  public function __construct(){
                               }

  public static function getobject()
  {
      $v = new person();
      return $v;
  }

}

class student extends person{

  public static $b = "World";

}

$st = student:getobject();//this will return person object but I want student object

echo $st->$b; // There is an error here because the object is not student
Run Code Online (Sandbox Code Playgroud)

所以我想知道要写什么来$v = new person();获取最后一个继承类的对象。

php oop inheritance class

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

Laravel 5 - SimplePaginate 函数在这里不起作用?

在直接simplePaginate()调用where()函数后,函数正在工作:

$posts = $userA->Posts()->simplePaginate(10)->get();
Run Code Online (Sandbox Code Playgroud)

User Eloquent 中的 Posts() 函数:

public function Posts(){
  return Post::where('user_id','$this->id')->where('category','programming');
}
Run Code Online (Sandbox Code Playgroud)

然而一切正常,但问题是当我拥有多个用户时,所以我做了这个:

//Creating Empty Collection (Working Without any problem)
$posts = new \Illuminate\Database\Eloquent\Collection;

//Getting and Adding the userA Posts (Working Without any problem)
$userA_Posts = $userA->Posts();
$posts = $posts->merge($userA_Posts);

//Getting and Adding the userB Posts (Working Without any problem)
$userB_Posts = $userB->Posts();
$posts = $posts->merge($userB_Posts);

//Getting and Adding the userC Posts (Working Without any problem)
$userC_Posts = $userC->Posts();
$posts = $posts->merge($userC_Posts);

//Here …
Run Code Online (Sandbox Code Playgroud)

php collections function laravel-5

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

在构建过程中无需用户交互就调用setState()

我做了什么 :

  • 我在flutter应用程序中集成了FCM(Firebase云消息传递)。
  • 我在静态变量中共享了每个页面的context和,setState()在页面的所有构建函数中调用了这两行:
@override
Widget build(BuildContext context) {
    StaticClass.currentContext = context;
    StaticClass.currentSetState = this.setState;
    return ... ;
}
Run Code Online (Sandbox Code Playgroud)
  • 我创建了一个回调来处理应用程序运行时即将到来的通知
fcm.configure( onMessage: (){
    StaticClass.currentSetState((){
        Navigator.pushNamed(StaticClass.currentContext, "/notifications");
  });
});
Run Code Online (Sandbox Code Playgroud)

发生了什么 :

  • 我收到此错误:
 ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY ????
...
setState() or markNeedsBuild() called during build.
This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets.
...
Run Code Online (Sandbox Code Playgroud)

说明:

  • 构建框架时,无法更新页面(通过使用上下文或调用setState())
  • 通过用户交互调用此函数时不会发生此问题

我想要的是 :

  • 有没有办法修复我的代码,或者我做错了什么?

要么

  • 触发onMessage()时,还有其他解决方案可转到另一个Page吗?

要么 …

setstate dart firebase flutter

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