草庐IT

php - Laravel 已售商品数量

我想计算每个卖家的已售商品。我尝试更改此代码:whereIn('seller_id',[4])->count();echo$count;?>我可以在其中添加其他$DB命令吗?{{$product->seller->id}}例如像这样而不是[4]:whereIn('seller_id',[{{$product->seller->id}}])->count();echo$count;?> 最佳答案 试试这个:在你的卖家模型中publicfunctionpurchases(){return$this->hasMany(Purchase::

php - Laravel 获取最后插入的数据

请找到下面的代码,我在这里尝试创建主记录并根据我添加相关数据的id。$country=newCountry;$country->name=$request->post('country-name');$country->xyz=$request->post('xyz');if($country->save()){$n=count($request->post('bname'));for($i=0;$iname=$request->post('bname')[$i];$dimention->xyz=$request->post('xyz')[$i];$dimention->cid=$co

php - 如何使用 Laravel 5.5 从多态关系中检索数据?

我是Laravel的新手。我正在使用PolymorphicRelations开发一个演示,遵循documentation我设置了3个表:--Users--id--username--Posts--id--summary--published--Images--id--link--alt--image_id--image_typeApp\Models\UserspublicfunctionscopeWithImages(){returnstatic::with('images')->get();}publicfunctionimages(){return$this->morphMany(

php - 有没有办法在 Symfony 4 中放置队列 worker ?

目前,我在Symfony4环境中工作,该环境需要定期(通过cron)处理命令/操作队列,而无需安装像RabbitMQ这样的服务器包。在Laravel中有一个宏伟的队列系统,它与数据库同步队列和一个监听器一起工作。Symfony4有这样的东西吗?我试过安装JMSJobQueueBundle和QueueBundle,但都无法在Symfony4中安装。 最佳答案 你有这个包https://github.com/php-enqueue/enqueue-dev提供了很多选择 关于php-有没有办法

php - 如何从 Laravel 正确模拟 Illuminate\Http\Request 类

我正在尝试测试一个类中的一个方法,该类包含一个使用Laravel的request()助手的方法。这是方法:类别类publicfunctiongetCanonicalUrl(){returnpreg_match('/\/sale\/./',request()->getRequestUri())?'':url($this->getUrlKey());}测试应该使这个帮助程序在执行getRequestUri()时正确捕获URI,但它实际上返回一个空字符串。这是我对测试进行的一千次尝试之一。测试publicfunctiontestCanonical(){//...$requestMock=Mo

php - 在 Laravel 5.5 中使用 '&' 而不是 '&apm;' 查询的数组

我正在尝试从数组构建查询。我确实尝试使用http_build_query函数,但结果是&而不是&因此,我尝试创建自己的函数,但出现此错误:ObjectofclassSymfony\Component\HttpFoundation\ParameterBagcouldnotbeconvertedtostring这是我的代码:$params=['foo'=>$reuest->foo,'baz'=>'boom','cow'=>'milk','php'=>'hypertextprocessor']$paramsJoined=array();foreach($paramsas$param=>$va

PHP MVC 框架 Laravel 似乎出错 Artisan Serve

这个问题在这里已经有了答案:Couldnotopeninputfile:artisan(24个答案)关闭5年前。通过键入创建项目后laravelnew"first-project"我正在写下面的代码但是会导致错误phpartisanserveCouldnotopeninputfile:artisanScreenshot

php - 在 Laravel 中发送邮件之前加载图像/栏

我想在服务器花时间将电子邮件发送给laravel中的指定用户时显示加载图像或栏。是否有任何laravel包可以这样做? 最佳答案 你应该使用queues为了那个原因。来自thedocs:Sincesendingemailmessagescandrasticallylengthentheresponsetimeofyourapplication,manydeveloperschoosetoqueueemailmessagesforbackgroundsending.Laravelmakesthiseasyusingitsbuilt-i

php - 复制整个模型的数据库并插入到同一个表中并更改列

好的。假设我有一个名为Questions的模型,它由管理员处理。每个问题都有一个名为master的列设置为true。我怎样才能做到这一点,以便我可以复制整个数据库表并将其复制到同一个表中,并将master列设置为false和user_id设置为其他值。我想知道是否有一种方法可以做到这一点,而不是用老式的方法。 最佳答案 刚刚测试了这个解决方案,它运行良好。根据您的意见:$questions=Questions::all();$questions=$questions->map(function($i)use($userId){$i=

php - 通过 auth 中间件重定向到自定义登录页面

在不生成Laravel默认身份验证Controller的情况下,我创建了自己的登录和注册Controller。我的路线是这样的登录GET/login->>SessionController@create-->name=login.createPOST/login->>SessionController@store-->name=login.store注册GET/registration->>RegistrationController@create-->name=register.createPOST/registration->>RegistrationController@stor