Comments (14)
I've been looking into this issue and found it relates to how Nova requests get the resource (it uses the route).
I've made a patch for this that i hope can help the development of a fix.
It's based on the laravel-5.8 branch and needs some refactoring, at least when it comes to naming.
Here it is:
issue-41-patch.txt
Hope it helps!
from laravel-nova-nested-form.
hi all :)
sorry for the (very) late reply. I just released v2.1.0 that includes both @KevinKodamera's patch and should be compatible with both Nova 1 & 2 (no need for the 5.8 special branch). Could you confirm this works as expected?
from laravel-nova-nested-form.
Try running composer dump-autoload
after applying the patch.
As for patches i recommend the cweagans/composer-patches package.
Then you can simply add the patch by adding the following to your composer.json file.
And it will (try to) apply the patch when running composer install
or composer update
.
"extra": {
"patches": {
"yassi/nova-nested-form": {
"Nested relations asks for required fields of parent": "https://github.com/yassipad/laravel-nova-nested-form/files/3085468/issue-41-patch.txt"
}
}
}
from laravel-nova-nested-form.
Patch proposed by @KevinKodamera seems to work.
Could you please create a new tag version of this fantastic plugin?
Thanks a lot 🥇
from laravel-nova-nested-form.
Hi,
Can you also show me the Answer resource? Have you tried without the DuplicateField?
from laravel-nova-nested-form.
Removing DuplicateField in both Question and Answer does not solve the issue (exact same error).
<?php
namespace App\Nova;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Select;
use Jackabox\DuplicateField\DuplicateField;
class Answer extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\Answer';
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'title';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id', 'title', 'value',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
BelongsTo::make('Question')
->searchable()
->rules('required'),
Text::make('title')
->sortable()
->rules('required', 'max:255'),
Text::make('value')
->sortable()
->rules('required', 'max:255'),
Select::make('status')->options([
'0' => 'System',
'1' => 'User',
])
->displayUsingLabels()
->rules('required'),
BelongsTo::make('Follow up', 'follow_up_question', 'App\Nova\Question')
->searchable()
->nullable(),
DuplicateField::make('Duplicate')
->withMeta([
'resource' => 'answers', // resource url
'model' => 'App\Answer', // model path
'id' => $this->id, // id of record
'relations' => [] // an array of any relations to load (nullable).
]),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [];
}
}
from laravel-nova-nested-form.
I'm sorry this does not solve my issue. But maybe I'm not knowing how to apply your fix correctly.
Composer
{
"yassi/nova-nested-form": "dev-laravel-5.8"
}
Then apply your fix in:
vendor\yassi\nova-nested-form
running git apply issue-41-patch.txt
This however give an error, saying I'm missing the files in src/Requests/*
So by adding empty files then applying you fix seems to work. Yet I do get the same error in Nova...
Thanks for your time anyways!
from laravel-nova-nested-form.
Thanks Kevin, this indeed does work!
@yassipad
from laravel-nova-nested-form.
Oke, I answered this a bit too quickly. Applying the patch seems to work, and after some changes in the Question and Answer Nova Resource it deed seem to work. But I'm stuck at the following error message when creating / updating answers:
{
"messages" : "The given data was invalid.",
"errors" : {
"answers[0][question]" : ["The question field is required."]
}
}
This is probably caused by this in the answer resource:
BelongsTo::make('Question')
->searchable()
->rules('required'),
Removing that part will allow me to update answers, but when I try to create them I do get another error message (logic):
{
"message": "SQLSTATE[HY000]: General error: 1364 Field 'question_id' doesn't have a default value (SQL: insert into `answers` (`title`, `value`, `status`, `follow_up`, `updated_at`, `created_at`) values (dd, aa, 0, 1, 2019-04-25 07:16:35, 2019-04-25 07:16:35))",
"exception": "Illuminate\\Database\\QueryException",
"file": "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
"line": 664,
...
}
So instead of removing that part from the answer resource, I've added something:
BelongsTo::make('Question')
->searchable()
->rules('required')
->hideWhenUpdating(),
This again allows me to update Answers, but once I want to add a new one I get the first error message again (logic):
{
"messages" : "The given data was invalid.",
"errors" : {
"answers[0][question]" : ["The question field is required."]
}
}
And I did try some more, but I'm always stuck at not being able to create a new answer. And also the above solutions are not feasible since you will remove the ability to create / update answers by "the normal Nova way"
from laravel-nova-nested-form.
I'm having the exact same issue; I've been digging through the code and watching the network & Vue devtools from Nova and it seems like it is sending empty GET parameters during the request: http://localhost:3001/nova-api/experiments/60?viaResource=&viaResourceId=&viaRelationship=
Which results in the parameter experiment_id
from the relationship not being set.
from laravel-nova-nested-form.
I'm having the exact same issue; I've been digging through the code and watching the network & Vue devtools from Nova and it seems like it is sending empty GET parameters during the request:
http://localhost:3001/nova-api/experiments/60?viaResource=&viaResourceId=&viaRelationship=
Which results in the parameter
experiment_id
from the relationship not being set.
I don't think the parameters are an issue, I've applied the patch provide by @KevinKodamera and everything works fine without the parameters. The problem is that it refer to the parent model when it is creating the children. This causes most of reported issues
from laravel-nova-nested-form.
v2.1.0 seems to work just as expected!
Thank you so much! 🎉
from laravel-nova-nested-form.
You're welcome, thanks so much for contributing :)
from laravel-nova-nested-form.
from laravel-nova-nested-form.
Related Issues (20)
- Global search is broken, when using NestedForm HOT 4
- Changing text when there is no data HOT 2
- Multiple subresources are created when Observer saves main resource again HOT 2
- How to pass a parameter to child nested form? HOT 7
- Help text is not displayed HOT 6
- The nested relationship model is often not yet available in the parent object observer created() method
- What's the best way to translate things in LNNF HOT 2
- Second nested form display index incorrect
- Nested form validation not working. HOT 1
- Nested Form not working after update laravel 7 and nova 3
- defining the inverse - Whats's wrong? HOT 2
- Touch related items
- Is there anyway to override file field
- Support for Laravel Nova Advanced media library HOT 2
- Slow result rendring while using with BelongsTo field
- Support for Laravel Nova 4 HOT 15
- How to hide relationship column
- Question: is it possible to show related resources not only when editing, but when viewing main resource too?
- Trying to get property 'resourceClass' of non-object
- The Add new Record button is not adding the correct index
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-nova-nested-form.