草庐IT

laravel_queue

全部标签

php - Ajax 成功后刷新/重新加载页面 - Laravel

在我的laravel项目中,我想在ajax成功后刷新我的页面,但我的页面会在成功后刷新。我尝试在Controller中使用laravelredirect进行刷新,但没有用,我也尝试在ajax中进行刷新,但什么也没发生?我该怎么做?我该怎么做?Controllerif(request()->ajax()){//dosomethingreturn['success'=>'successfullydone'];returnredirect('admin/all')->with('status','Successfullydone!');JS$('#master').on('click',fu

php - Laravel phpunit assertViewHas 与预期的测试数据不匹配

我正在为我的搜索方法编写测试,但目前有一个assertSee并且想将其更改为assertViewHas以获得更好的测试结果。但是我从搜索方法中获得的数据与我期望的数据不匹配。这是我设置$user的地方:protected$user;publicfunctionsetUp(){parent::setUp();$this->seed();$this->user=factory(User::class)->create(['role_id'=>3]);}这是我做出断言的地方:$response=$this->followingRedirects()->actingAs($this->user

php - 如何在 laravel 5.5 中监听 messageSent 事件

大家好,我是laravel事件和监听器的初学者。所以请向我解释如何实现这一目标:目标:向用户发送电子邮件。并知道电子邮件是否已发送。我的理解:Laravel有内置事件Illuminate\Mail\Events\MessageSent在电子邮件发送后触发,我必须编写一个监听器来监听该事件。我做了什么:发送电子邮件:Mail::to($receiverAddress)->send(newSendNewUserPassword($content));这工作正常。能够成功地向用户发送电子邮件。为了监听messageSent事件,我创建了这个监听器:message;}}注册事件:protect

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 - 如何从 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