我有一个卖方对象,其中有一个相关的用户.我需要填写LaravelCollective的一个选择,所以我需要做这样的事情:
{!! Form::selectGroup('seller_id', 'Seller', Seller::with('user')->pluck('user.first_name', 'id')->toArray(), null) !!}
Run Code Online (Sandbox Code Playgroud)
问题是我无法从关系中获取字段(user.first_name).
我该怎么做?
UPDATE
我想避免这样做......
<?php
$sellers = [];
Seller::with('user')->get()->each(function ($seller) use (&$sellers) {
$sellers[$seller->id] = $seller->user->first_name;
});
?>
Run Code Online (Sandbox Code Playgroud) 我知道还有很多其他问题出现在同一个错误中,例如:类'Illuminate\Html\HtmlServiceProvider'找不到Laravel 5
我的问题是我已经按照所有建议的步骤在我的本地(XAMPP)上解决了这个问题,并且它没有任何障碍.问题是当我去部署到我的AWS ubuntu框(nginx)时.我按照所有常用说明操作:http://laravelcollective.com/docs/5.1/html#installation
我从我当地推出的git pull中添加了我的提供者和别名.也许这个文件应该被gitignored,并且在服务器上手动进行更改?
Next, add your new provider to the providers array of config/app.php:
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
Finally, add two class aliases to the aliases array of config/app.php:
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
Run Code Online (Sandbox Code Playgroud)
然后我手动添加:
Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/html.
"require": {
"laravelcollective/html": "5.1.*"
}
Run Code Online (Sandbox Code Playgroud)
最后,我跑了:
composer.phar update
Run Code Online (Sandbox Code Playgroud)
它正在运行此命令抛出错误: …
我正在尝试添加垃圾图标以提交按钮,我试过这个:
{!! Form::submit('', ['class' => 'btn btn-warning btn-sm fa fa-trash']) !!}
Run Code Online (Sandbox Code Playgroud)
但图标不会显示.怎么解决这个?提前致谢!
我用Laravelcollective/html v5.3.0用laravel 5.3.现在我正在使用laravel 5.4.我有正在使用的表格Laravelcollective/html v5.3.0.
该composer require laravelcollective/html给我下面的错误:
Installation request for laravelcollective/html ^5.3 -> satisfiable by laravelcollective/html[v5.3.0].
-Conclusion: remove laravel/frameworkv5.4.0
- Conclusion: don't install laravel/framework v5.4.0
Run Code Online (Sandbox Code Playgroud)
什么时候laravel 5.4支持Laravelcollective/html?
通过这个SO线程阅读我已经读过我可以创建一个新的宏来创建自定义表单输入.
我对Laravel开发来说是一个全新的(大惊喜),对于这么小的事情来说似乎有点过分.是否有一种"更简单"的方式来做这样的事情:
刀片模板
{!!Form::label('firstName', 'First Name<sup>*</sup>') !!}
{!! Form::text('firstName', null, ['class'=>'required']) !!}
Run Code Online (Sandbox Code Playgroud)
HTML
<label for="firstName">First Name*</label>
<input type="text" name="firstName" class="required">
Run Code Online (Sandbox Code Playgroud)
或者,这是一个我只是编写html,然后使用表单服务来创建输入的情况?
感谢您的耐心和洞察力.
我正在尝试从数据库中检索数据并将它们绑定到html选择标记,并绑定它们我需要使用pluck所以我得到我希望在数组中显示的字段(key => value),因为FORM: :选择.正常的采摘获得所有结果,而我想使用不同的.我的模特是房间,它看起来像:
class Room extends Eloquent
{
public $timestamps = false;
protected $casts = [
'price' => 'float',
'floor' => 'int',
'size' => 'float'
];
protected $fillable = [
'capacity',
'description',
'price',
'floor',
'size',
'type',
'photo_name'
];
}
Run Code Online (Sandbox Code Playgroud)
虽然我在控制器中使用的功能看起来像:
public function getRooms()
{
$roomType = Room::pluck('type','type');
$roomFloor = Room::pluck('floor','floor');
return view('roomgrid')->with('type',$roomType)->with('floor',$roomFloor);
}
Run Code Online (Sandbox Code Playgroud)
我的视图包含这段代码来获取楼层:
{{FORM::select('floor', $floor, null,['class'=>'basic'])}}
Run Code Online (Sandbox Code Playgroud)
像这样我得到重复的地板,我不想要.有什么办法让我可以得到不同的地板并采摘它们吗?提前致谢.
我有一个表单,里面我有一些选项,我使用Laravel Collective Forms来构建它,我有类似的东西:
{!! Form::select('size', $data, $selecteds, ['multiple' => true]) !!}
Run Code Online (Sandbox Code Playgroud)
一切顺利,直到这里,但现在我需要data-section为每个选项设置一个属性,我该怎么做呢?
在我的视图页面中,我有这条路线:
{!! Form::open(['url' => 'forumcomment/' . $forum->slug, 'files'=>false, 'id' => 'qw-commentform' ,'class' => 'qt-clearfix']) !!}
<hr class="qt-spacer-s"><div class="input-field">
{!! Form::textarea('comment', null, ['class'=>'materialize-textarea', 'id'=>'my-editor', 'required'=>'required','aria-required'=>true]) !!}
<label for="comment" class="">Comment*</label></div>
<hr class="qt-spacer-s">
{!! Form::submit('Post Comment', array( 'class'=>'qt-btn qt-btn-primary qt-btn-xl' )) !!}
{!! Form::close() !!}
Run Code Online (Sandbox Code Playgroud)
混合内容错误如何获得安全路线?
我更新composer.json了删除illuminate\html并添加:
"require": {
"laravelcollective/html": "5.1.*"
Run Code Online (Sandbox Code Playgroud)
我从app.phpIlluminate\Html中删除了提供者/别名并添加了替换:
Collective\Html\HtmlServiceProvider::class,
Run Code Online (Sandbox Code Playgroud)
...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
Run Code Online (Sandbox Code Playgroud)
但是在运行时composer update我会收到输出:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing illuminate/html (v5.0.0)
- Installing laravelcollective/html (v5.1.4)
Downloading: 100%
Writing lock file
Generating autoload files
> php artisan clear-compiled
PHP Fatal error: Class 'Illuminate\Html\HtmlServiceProvider' not found in vendor/laravel/framework/src/Illuminate/Foundation/Application.php on line 648
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Illuminate\Html\HtmlServiceProvider' not found
Script php artisan clear-compiled handling the post-update-cmd event …Run Code Online (Sandbox Code Playgroud) 我使用laravel 5.3为我的项目,我使用laravel形式集体到它的代码如下
{{ Form::select('size', ['surat' => 'surat', 'mumbai' => 'mumbai','hongkong' => 'hongkong'], 'hongkong',['multiple'=>'true'], array('class'=> 'form-control') ) }}
但 array('class'=> 'form-control') 如果我删除['multiple'=>'true']它然后它正常工作,这对我不起作用,所以我如何将bootstrap类应用于我的选择框.
laravel ×8
php ×5
laravel-5 ×4
laravel-5.2 ×2
css ×1
distinct ×1
forms ×1
html ×1
laravel-5.1 ×1
laravel-5.3 ×1
pluck ×1