laravie / html Goto Github PK
View Code? Open in Web Editor NEW๐จ HTML and Form Builders for the Laravel Framework
License: MIT License
๐จ HTML and Form Builders for the Laravel Framework
License: MIT License
Form model binding not working in blade components
Form model binding is not working when you create a form component:
@component('components.form', ['model' => $product ?? null, 'route' => 'products'])
@component('components.form-group', ['name' => 'name', 'label' => 'Product name:'])
{!! Form::text('name', null, ['class' => 'form-control']) !!}
@endcomponent
@endcomponent
And components/form.blade.php looks like this:
{!! Form::model($model, ['method' => 'PATCH', 'route' => [$route . '.update', $model->id]]) !!}
{!! $slot !!}
{!! Form::close() !!}
In this case the field values are not populating (the attributes are exist in the $model object). When I use Form::model() just where I make the fields, it's working fine. If I @include the form opener part, it's also working fine.
Thank you.
Hi there,
This is probably just a misunderstanding of my part but there's something strange related to the FormAccessible trait when dealing with relations.
First of all, is this trait supposed to be dealing with relations ? Or is the developer expected to write form mutators for relations ? If so, just ignore this :)
So I've got this model that defines a relation :
class Content {
use FormAccessible;
public function content_type()
{
return $this->belongsTo(ContentType::class);
}
}
if I call $content->getFormValue('content_type')
it returns null, because :
1 - there is no form mutator for content_type in this model
2 -The FormAccessible trait sees 'content_type' as a nested key and forward the call like so :
return \data_get($relatedModel, empty($key) ? null : $key);
with, in this case, $relatedModel being a ContentType object and $key being still 'content_type'.
Obviously there is no 'content_type' attribute on the ContentType object.
Moreover, if I call $content->getFormValue('content_type.id')
it's searching for a form mutator in ContentType called formContentType.idAttribute
on the ContentType object, which isn't a valid php method name.
Wouldn't it make more sense to return the ContentType object when there is no form mutator in that object, or even better the key of the relation if the key isn't a nested key ?
So it would do :
$content->getFormValue('content_type'); //returns the primary key of the ContentType object
$content->getFormValue('content_type.name'); //returns a string or the result of the method formNameAttribute of the ContentType object
What do you think ?
Hello,
I try to install the library on Laravel 9 but I have the following errors:
Problem 1
- illuminate/view[v7.0.0, ..., v7.28.4] require php ^7.2.5 -> your php version (8.1.0) does not satisfy that requirement.
- illuminate/view[v8.0.0, ..., v8.11.2] require php ^7.3 -> your php version (8.1.0) does not satisfy that requirement.
- Root composer.json requires laravie/html dev-master -> satisfiable by laravie/html[dev-master].
- Conclusion: don't install laravel/framework v9.3.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.3.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.2.0 (conflict analysis result)
- laravie/html dev-master requires illuminate/view ^7.0 || ^8.0 -> satisfiable by illuminate/view[v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev].
- Only one of these can be installed: illuminate/view[v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev], laravel/framework[v9.2.0, v9.3.0, v9.3.1, 9.x-dev]. laravel/framework replaces illuminate/view and thus cannot coexist with it.
- Root composer.json requires laravel/framework ^9.2 -> satisfiable by laravel/framework[v9.2.0, v9.3.0, v9.3.1, 9.x-dev].
Can you update your library for Laravel 9?
Thank you!
When using renderComponent, it tries to return an instance that implements "Htmlable".
But since it is not aliased, an ErrorException is thrown:
Type error: Return value of Collective\Html\FormBuilder::renderComponent() must be an instance of Collective\Html\Htmlable, instance of Illuminate\Support\HtmlString returned
After adding
use Illuminate\Contracts\Support\Htmlable;
into src/Componentable.php, the problem disappears as expected.
Hey,
Seems like there is a bug with the the following method:
https://github.com/laravie/html/blob/master/src/Concerns/Selection.php#L203
Assuming the following code as an example.
getSelectedValue(1, collect([1,2,3]))
the first lines in the method mentioned above will kick in for arrays as well as collections since Collection implements Arrayable.
the code
} elseif ($selected instanceof Collection) {
return $selected->contains($value) ? 'selected' : null;
}
never executes for Collections.
The following seems to work
/**
* Determine if the value is selected.
*
* @param string|null $value
* @param string|iterable|null $selected
*
* @return string|null
*/
protected function getSelectedValue(?string $value, $selected): ?string
{
if ($selected instanceof Collection) {
return $selected->contains($value) ? 'selected' : null;
} elseif ($selected instanceof Arrayable) {
$selected = $selected->toArray();
}
if (is_array($selected)) {
return in_array($value, $selected, true) || in_array((string) $value, $selected, true)
? 'selected'
: null;
}
return ((string) $value === (string) $selected) ? 'selected' : null;
}
Looking at the source code
https://github.com/laravie/html/blob/7.x/src/HtmlBuilder.php#L261
https://github.com/laravie/html/blob/7.x/src/HtmlBuilder.php#L282
seems like the $secure variable is not defined but used
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.