草庐IT

php - Laravel 同步不适用于空数组

我有一个看起来像这样的方法:publicfunctionsaveContacts(Request$request){if($request->contacts){$contacts=collect($request->contacts)->pluck('id');$this->contacts()->sync($contacts->toArray());}}它可以工作,但如果$request->contacts是一个空数组,它不会删除所有记录。这里可能是什么情况? 最佳答案 你可以这样做:if($request->contacts)

php - 如何在 View 中访问 Laravel 类?

如果我在controller中,这行就可以了。使用App\UBBUserSetting,App\UBBSetting;但我在视野中我试图在我的View中包含我的类(.blade.php)我不能useApp\UBBUserSetting,App\UBBSetting;$ubb_user_settings=UBBUserSetting::where('cpe_mac','=',$cpe_mac)->get();$ubb_settings=UBBSetting::where('cpe_mac','=',$cpe_mac)->first();if($ubb_settings!=null){$j

php - Laravel:非复合名称 'Cache' 的 use 语句无效

这个问题在这里已经有了答案:Laravel/Composer:Theusestatementwithnon-compoundname(1个回答)关闭5年前。我有centos7php56laravel5和memcached但是当尝试使用缓存在routes.php我得到:ErrorExceptioninroutes.phpline3:Theusestatementwithnon-compoundname'Cache'hasnoeffect路由器.php

php - 将名称添加到 laravel 路由

我有一条路线定义为:Route::get('/novanoticia','HomeController@getNovaNoticia');当我运行phpartisanroute:list时,名称列中没有任何显示。如何以这样一种方式向路由添加名称,以便我以后可以仅通过其名称来调用它,例如:href="{{route('route_name',$routeparam)}}?或者我必须重新定义路线吗?提前致谢 最佳答案 选项1Route::get('/novanoticia','HomeController@getNovaNoticia'

php - Laravel - 未签名且可为空

我正在使用Laravel5.3,我想在表迁移中定义一个字段为nullable以及unsigned。由于两者都是索引修饰符,我可以将它们串联使用吗?喜欢:$table->integer('some_field')->unsigned()->nullable();如果laravel文档或其他地方有此类修改,也请提供一些引用。请注意,我想将up()函数中的字段定义为无符号且可为空。我不想要具有down()功能的解决方案,例如:publicfunctionup(){Schema::create('ex',function(Blueprint$table){$table->integer('so

php - Laravel 通知电子邮件门面队列多个用户

这是我的代码,用于向多个用户发送通知电子邮件$users=User::whereIn('id',$userIds)->get();\Notification::send($users,newDealPublished($deal));它有效,但如果我想那样延迟它$users=User::whereIn('id',$userIds)->get();$when=Carbon::now()->addSecond();\Notification::send($users,newDealPublished($deal))->when($when);错误是FatalThrowableErrorin

php - 显示存储 laravel 5.3 中的图像

我是laravel框架的新手,我想显示存储在存储文件夹中的图像。这个我试过了路线Route::get('/userimage/{filename}',['uses'=>'PostController@getUserImage','as'=>'account.image',]);blade文件获取url并显示图片@if(Storage::disk('public')->has($user->first_name.'-'.$user->id.'.jpg'))$user->first_name.'-'.$user->id.'.jpg'])}}"alt=""class="img-respons

php - 在 Laravel 5.4 中更改密码

我已经在我的网络应用程序中添加了更改密码的代码。但是Hash::check()不起作用。始终返回false。此外,Hash::Make()每次都会返回不同的字符串。我试过bcrypt()但它也不起作用。请帮我。这是我的代码。publicfunctionchangePassword(Request$request){$user=Auth::user();$curPassword=$request->input['curPassword'];$newPassword=$request->input['newPassword'];if(Hash::check($curPassword,$us

php - Laravel 5.4 密码重置

我有一个Laravel5.4应用程序,我在我的管理区域中有一个View,允许我查看所有用户。我想创建一个函数,允许我点击后端的一个按钮,自动发送默认的Laravel密码重置功能。在我看来,我有以下几点:#CompanyNameEmailAddressAction@foreach(\App\User::all()as$c){{$c->id}}{{$c->company->company_name}}{{$c->name}}{{$c->email}}id}}/password/reset">PasswordReset@endforeach在当前通过我的路线点击重置密码的链接上点击以下功能p

php - Laravel 保存($request->all()) 错误

我有一个问题,我一直在开发laravel应用程序,我遇到了这个奇怪的错误:QueryExceptioninConnection.phpline770:SQLSTATE[23000]:Integrityconstraintviolation:1452Cannotaddorupdateachildrow:aforeignkeyconstraintfails(`testenv`.`products`,CONSTRAINT`products_tenant_id_foreign`FOREIGNKEY(`tenant_id`)REFERENCES`tenants`(`id`))(SQL:inser