我正在尝试创建((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变量是未定义的,请帮忙,我正在尝试显示两个用户的消息,我还想我可以单独获取第一个(在哪里和哪里)然后得到第二个,然后我将合并它们.
我正在尝试获取上个月的所有记录,到目前为止,我设法从上个月获取了所有记录,但是到目前为止,我不确定如何只获取上个月的记录
$revenueMonth = Callback::where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->sum('payment');
Run Code Online (Sandbox Code Playgroud) 我有两个类(模型和用户),但我有一个问题所以我试图在一个简单的例子中解释它:
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)
请给我一个解决方案,但没有在学生班写任何功能我只想在那里做声明:)谢谢:)
我的模型类和其他类有一些问题,所以我做了这个简单的例子来解释我的问题:
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();获取最后一个继承类的对象。
在直接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) 我做了什么 :
context和,setState()在页面的所有构建函数中调用了这两行:Run Code Online (Sandbox Code Playgroud)@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. ...
说明:
我想要的是 :
要么
要么 …
php ×5
eloquent ×2
inheritance ×2
class ×1
collections ×1
dart ×1
firebase ×1
flutter ×1
function ×1
laravel ×1
laravel-5 ×1
laravel-5.2 ×1
mysql ×1
oop ×1
php-carbon ×1
setstate ×1
where-clause ×1