草庐IT

php - Laravel:如何在 Controller 方法执行后重定向

web.php:Route::post('caption/{id}/delete','DetailController@deleteCaption');DetailController.php:publicfunctiondeleteCaption(Request$request,$id){$caption=Caption::findOrFail($id);$caption->delete();//doesn'tdeletepermanentlyreturnresponse(204);}admin.blade.php:id}}'>{{$caption->content}}id}}/de

php - Laravel 授权中间件 : Class can does not exist

我正在尝试通过中间件保护路由describedinthedoc当我点击url时,我得到:ReflectionExceptioninContainer.phpline749:Classcandoesnotexist这是来自routes.php的相关部分:Route::get('{user}/profile/edit/{type?}',['as'=>'edit','uses'=>'User\UserController@edit','middleware'=>['can:edit-user,user'],]);AuthServiceProvider.php:publicfunctionbo

php - WhereIn Eloquent 形式

我有两个数组temp[]time[]例如,如果我的数组中有这样的数据temptime[0]8045[1]7050[2]8565[3]9030我想根据这两个数组参数查询数据像(select*fromMyTablewhere(temperature=80andtime=45))forthenext(select*fromMyTablewhere(temperature=70andtime=50))等等我正在做这样的事情$mix=MyTable::whereIN('temperature',$temp)->whereIN('time',$time)->where('category',$ca

php - 我们可以将@yield 的值存储在变量中吗

我有一个简单的问题,我们能否将产生的值存储在变量中。举个例子$var=@yield('title')如果不是,那么有什么方法可以得到这个yield的值 最佳答案 是的,您可以检索由section定义的yield的值,例如://Assumedyou'vethefollowinginyourview:@section('title','SomeTitle')$title=app()->view->getSections()['title'];//SomeTitle基本上,app()->view->getSections()将返回所有部分

php - Laravel - diffForHumans 德语

我正在尝试在laravel5.2中使用德语的Carbon的diffForHumans()显示created_at属性。created_at在数据库中存储为:2017-03-2917:31:52模型protected$dates=['created_at','updated_at'];publicstaticfunctiongetCreatedAtAttribute($value){Carbon::setLocale('de');returnCarbon::parse($value,'Europe/Berlin')->diffForHumans();}dd($value);返回"2017

php - LARAVEL - 显示存储文件夹中的图像

我是Laravel的新手,想知道是否有人可以通过简单的图片上传来帮助我。我有一个表单,允许用户在此过程中创建个人资料并上传个人资料和头像。这一切都很完美。这是来self的Controller的代码:if(request()->hasFile('avatar')){$file=request()->file('avatar');$file->storeAs('avatars/'.auth()->id(),'avatar.jpg');}图片保存在storage/app/avatars/USER-ID/avatar.jpg我不确定如何显示此文件夹中的图像。我一直在寻找解决方案,但我无法使用p

php - 通过 AWS EC2 上的 cron 安排 Laravel 5 - 命令未运行

问题:我有一个Laravel5.4artisan任务,我需要通过cron运行-但尽管命令和调度程序(显然)设置正确,但它没有完成。这是Laravel、php、apache、linux还是crontab问题?最好的诊断方法是什么?背景在默认(亚马逊AMI)EC2实例上,artisan命令被正确定义并在通过以下方式调用时从项目目录(/var/www/html/myproject/)完美运行:phpartisanmycommand:option1我已将其添加到app/Console/Kernel.php中,如下所示:protectedfunctionschedule(Schedule$sch

php - 如何在 Eloquent laravel中检查hasMany关系记录为空

我需要获取那些没有加入的记录有很多表我的查询是这样的$result=Recipes::select('id')->where("name",'like','%'.$item.'%')->with(['categoryItem'])->get();我的输出是Array([0]=>Array([id]=>1[category_item]=>Array([0]=>Array([id]=>2[foodable_id]=>1[foodable_type]=>Recipes[created_at]=>2017-04-1416:18:22)))[1]=>Array([id]=>4[category_

php - 无法打开流 : No such file or directory on Homestead environment

我正在使用homestead环境,命令行“phpartisan-V”不起作用。我用“laravelnewtest”创建了我的项目,所以..我想我的所有文件都已更新。vagrant@homestead:~/Laracasts/test$phpartisan-VPHPWarning:require(/home/vagrant/Laracasts/test/bootstrap/autoload.php):failedtoopenstream:Nosuchfileordirectoryin/home/vagrant/Laracasts/test/artisanonline16Warning:r

php - laravel 5.4 php artisan serve 无效请求(意外的 EOF)

我正在使用Windows10和wamp服务器,我刚刚安装了laravel,我得到的只是这条错误消息,每次我打开laravel时是否有必要执行phpartisanserve?只要我关闭cmd提示localhost:8000refusedtoconnect。Phpartisan服务错误 最佳答案 我认为您正在通过phpartisanserve命令运行Laravel项目blog并且您正在通过localhost:8000或127.0.0.1:8000浏览您的应用程序您的屏幕截图显示,当您尝试访问未在routes/web.php中定义的url