草庐IT

laravel-censor

全部标签

php - 我如何向 Laravel 的 auth()->user() 对象 + 它的关系添加更多数据?

我的user模型有一个外键引用,叫做person_id,它指的是我的people表中的一个person.当我死亡并转储经过身份验证的用户(dd(auth()->user()))我得到:{"id":1,"email":"foo@bar.baz","is_enabled":1,"person_id":3,"created_at":"2017-12-1210:04:55","updated_at":"2017-12-1210:04:55","deleted_at":null}我可以通过调用auth()->user()->person来访问person但这是一个原始模型。Person的Pres

php - 如何将多维集合(数组)展平为宏(Laravel)中的点符号版本?

示例输入为json{"user":{"name":"Thomas","age":101},"shoppingcart":{"products":{"p1":"someprod","p2":"someprod2"},"valuta":"eur","coupon":null,"something":["bla1","bla2"]}}预期输出['user.name'=>'Thomas','user.age'=>101,'shoppingcart.products.p1'=>'someprod',...'shoppingcart.something.1'=>'bla1']我已经编写了这个函数,

php - Laravel 5.4 存储链接

我想在html文件中显示图片我转到链接文件夹public/storage/image是空的,但在storage/image中我找到了文件和它也保存在数据库中。*@foreach($cvsas$cv)photo)}}"alt="...">{{$cv->titre}}{{$cv->presentation}}AfficherModifierSupprimer@endforeach 最佳答案 首先在.env文件中创建一个名为FILESYSTEM_DRIVER的变量并将其设置为public像这样FILESYSTEM_DRIVER=publi

php - 如何在 Laravel 模型工厂中使用 trait?

如果Modelfactroy如下所示,那么如何在这里使用TraitgetData()?此代码无效。define(App\Working::class,function(Faker\Generator$faker){...$getData=$this->getData();...return['get_data'=>$getData];}错误信息:Symfony\Component\Debug\Exception\FatalThrowableError:调用未定义的方法Illuminate\Database\Eloquent\Factory::getData()异常跟踪:1Illumin

php - 在 Laravel 表单中使用 PUT 和 DELETE 方法时出现 MethodNotAllowedHttpException

我正在使用Laravel进行基本的CRUD。在Laravel表单操作中使用PUT和DELETE方法时出现MethodNotAllowedHttpException。GET和POST操作方法工作正常。 最佳答案 HTML表单只接受GET或POST方法所以你不能使用PUT和DELETE在形式方法中。但是,如果您想使用PUT或DELETE然后laravel提供Formmethodspoofing像这样这是表单示例简写@method('PUT')@csrf路线Route::put('foo/bar','FooController@bar')

php - 如何隐藏 laravel 中的关系列?

我有这样的声明:App\User::with('client')->find(2)->makeHidden('client.phone_no');我想从关系中隐藏某些列,但我不能用makeHidden()做到这一点,因为它只接受Model的参数而不是关系。如何从关系中隐藏某些列? 最佳答案 如果您不想通过将phone_no添加到hidden属性来隐藏所有请求的phone_no,您可以这样做:$user=App\User::with('client')->find(2);$user->client->makeHidden('phone

php - Laravel 中效用函数的含义是什么

大家好,我是Laravel的新手,我遇到但无法理解的是框架中使用的实用方法,例如,Customer::all()其中Customer是模型或Customer::find()。那么,实用方法的意义何在?为什么all()和find()是静态的。 最佳答案 实用程序函数通常提供某种实用程序,即通常只是为了方便起见并且也可以通过遵循一组步骤来实现的功能。例如Model::find()是也可以通过创建查询构建器对象然后执行查询来实现的功能,例如Model::getQuery()->where('id','=',$id)->first();为方

php - 使用 Laravel Collective 选择输入

{!!Form::select('country',['1'=>'Albania','2'=>'Kosovo','3'=>'Germany','4'=>'France'],null,['class'=>'form-control','placeholder'=>'SelectCountry'])!!}这种类型的输入不采用数组的值,而是采用select中选项的预默认值。在此处输入代码 最佳答案 根据FormCollectivedocumentation,Form::select()的第一个参数是select框的name,第二个是arr

php - Laravel 5.7 无法找到名称为 [default] [App\User] 的工厂

Laravel5.7工厂有什么进展?当我在phpartisantinker上运行工厂时,它工作正常。但是当我将它与单元测试一起使用时,它会抛出一个错误:Unabletolocatefactorywithname[default][App\User]这是我的单元测试user=factory(User::class,1)->create()->first();}/***@test*/publicfunctiona_sample_test(){$this->assertTrue(!empty($this->user));}}UserFactory是通过运行生成的phpartisanmake:

php - Laravel 中的电子邮件验证规则

我正在以这种方式进行验证。$rules=['email'=>'required|regex:/^.+@.+$/i|unique:tab_example,email,'.$this>get('example_id').',example_id'];return$rules;但是,我没有获得成功。错误提示theemailalreadyexists我想要的是如果邮件已经存在并且来自同一个用户不需要通知邮件已经存在。我不知道我的代码有什么问题。 最佳答案 你可以使用'email'=>"required|email|unique:users,