草庐IT

laravel-censor

全部标签

php - 在 Laravel 中将依赖参数传递给 App::make() 或 App::makeWith()

我有一个使用依赖项的类。我需要能够根据Controller的依赖项动态设置参数:$objDependency=newMyDependency();$objDependency->setSomething($something);$objDependency->setSomethingElse($somethingElse);$objMyClass=newMyClass($objDependency);我如何通过Laravel中的服务容器实现这一点?这是我尝试过的,但这对我来说似乎是错误的。在我的AppServiceProvider中:$this->app->bind('MyClass'

php - 如何验证 laravel 中的多条记录插入?

我的应用程序有一个表单,我可以在其中插入多条记录,每条记录都是一个新表单。我想验证我尝试使用验证函数的每个表单中的每个字段,但我很困惑如何为多个记录插入?对于这个项目,我使用的是laravel5.2。多次插入的存储函数publicfunctionstore(Request$request){$this->validate($request,['name'=>'required|min:4','fname'=>'required','rollno'=>'required|unique:students']);$input=$request->all();$condition=$input

php - laravel 构造函数重定向

我有一种方法可以检查用户的角色是否是管理员,如果不是,则使用returnredirect('/')->send();重定向他们。如何在不显示页面并等待重定向的情况下检查用户角色并重定向用户?我的Controller:classAdminControllerextendsController{publicfunction__construct(){if(Auth::check()){$user=Auth::user();if($user->role!='admin'){returnredirect('/')->send();}}else{returnredirect('/')->send

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