草庐IT

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 - 拉维尔 5 : How to use 'where' or 'orderBy' using eloquent?

首先,这不是Laravel4:howto"orderby"usingEloquentORM的副本我有这个模型User,然后我有这个模型Idea。我正在写一个包含用户详细信息的View,我想发布用户提出的所有想法。现在,想法有一个状态,第一个状态是“草稿”,这意味着只有发布想法的用户可以查看它,不应向查看个人资料的其他用户显示该想法。使用eloquent我可以做类似的事情:@foreach($user->ideaas$idea)...displaydetails...@endforeach我的问题是这种方法会循环遍历所有想法并按照它们被引入的顺序。我可以添加一个@if来仅显示我想要的内容

php - 将 [title] 添加到可填充属性以允许对 [App\Post] 进行批量分配

在Mysql中插入数据时遇到如下错误:“将[title]添加到可填充属性以允许对[App\Post]进行批量分配。”这是我的代码:$post=Post::create(['title'=>$request->input('title'),'body'=>$request->input('body')]);当我使用另一种方式插入数据时,它工作正常:以下代码工作正常://CreatePost$post=newPost;$post->title=$request->input('title');$post->body=$request->input('body');$post->save()

PHP fatal error : Allowed memory size of 1073741824 bytes exhausted (tried to allocate 16777216 bytes)

我在我的16GBMacBookPro上运行了composerinstall,我得到了这个⚡️distributor-portalcomposerinstallLoadingcomposerrepositorieswithpackageinformationUpdatingdependencies(includingrequire-dev)PHPFatalerror:Allowedmemorysizeof1073741824bytesexhausted(triedtoallocate16777216bytes)inphar:///usr/local/bin/composer/src/Co