Laravel Nova - How can i do custom logic on Create/Update - laravel

I would like to create custom Create/Update logic for one of my Nova Resource. I have been thinking to use Custom Tools to accomplish what i wanted, but i don't want to give up the excellent work in the Index page and rewrite it all myself.
My use case:
I want to have an input that can define how many record to be created recursively.
I want to have morphToMany selection input in the form.

If you want to use different components on the index vs form/detail page just use the hideFromIndex and onlyOnIndex functions.
Detailed reference to docs: https://nova.laravel.com/docs/1.0/resources/fields.html#showing-hiding-fields
If you want to build repetitive fields, you can use the package: https://packagist.org/packages/fourstacks/nova-repeatable-fields

Related

Why does Laravel group RESTful methods the way they do?

I'm brand new to Laravel and am working my way through the Laravel 6 from Scratch course over at Laracasts. The course is free but I can't afford a Laracasts membership so I can't ask questions there.
I've finished the first several sections of the course and am a little confused about some of the concepts around the whole RESTful idea. The instructor, who seems very good and experienced with Laravel, describes 7 methods that are going to be part of pretty much any CRUD (Create Read Update Delete) application (and most applications are CRUD in nature.) He says naming of these 7 methods should be consistent with this:
index - a list of all the resources in a collection e.g. all articles in a blog
show - display a specific resource from a collection e.g. a specific article in a blog
create - create a new instance of a resource e.g. add a new article to a blog
store - save a new instance of a resource to a data store like a database
edit - modify the contents of an existing resource e.g. change the title of an article
update - save the modified resource to a data store
destroy - remove a resource from a collection e.g. delete a blog article
I'm a little puzzled by this division of work into 7 separate methods. It seems to me that Create and Store belong together in a single method; ditto for Edit and Update. Creating a new record has two phases: displaying an empty form to gather up the data needed to construct a new article, then validating the data and storing it on the database. By the same token, changing an existing record consists of two phases: displaying the current data in a form and letting the user change what needs changing, then validating it and sending it to the database (or back to the user for corrections).
I would also argue that to be consistent with the approach they've used for create/store and edit/update, destroy should be divided into two methods, Destroy and Remove, where Destroy displays the full record that the user wants to remove with two buttons at the bottom: Delete and Cancel. Then, if the user clicks on Delete, they go to a Remove method that actually deletes the record f from the database.
I've been coding for a fair while and I've never seen a system where the user was allowed to delete any important record without first being shown the record and being asked if they're sure they want to delete it. Now, maybe that's fallen out of fashion and I didn't notice but it seems a pretty prudent thing to do.
So why are the methods what they are, at least as RESTful is implemented in Laravel?
It seems to me that Create and Store belong together in a single method
Well, Laravel generate all those methods thinking in a server-side rendered app. So in a SSR, before you store your data, you must be able to see a creation form.. that's why this create() function exists. The create(), normally, should return a view that will show the user the valid fields to create a resource, this is all done in a GET request. Then, when the users hit the "create"/"add" button, it will reach the store() method that will implement the logic to persist this data storing a new record in your database, this is done in a POST request.
The same goes for edit()/update().
I've been coding for a fair while and I've never seen a system where the user was allowed to delete any important record without first being shown the record and being asked if they're sure they want to delete it
That is because those validations are commonly implemented in the client-side, so, you do this with JS in your front-end, for validations of that kind you shouldn't hit the server.
So why are the methods what they are, at least as RESTful is implemented in Laravel?
Finally, for a RESTful API you don't need all of those methods. Just index, show, store, update and delete ones. If you just need this kind of methods in your controller, you could exclude the create/edit ones by adding the --api flag when creating your controller through Artisan. From the documentation:
API Resource Routes
// ...
To quickly generate an API resource controller that does not include the create or edit methods, use the --api switch when executing the make:controller command:
php artisan make:controller API/PhotoController --api

Is there any way that we can loop a function in a controller for multiple data validation?

I'm having a problem related to multiple data validation and want to know if there is any solution for loop condition of a function in a controller.If any please provide the solution.
I had tried using for loop but that dosent seem to work on Laravel Controllers
by default laravel supports multiple rules for validation, you have add | between the rules, like required|numeric|unique:posts. laravel will check the rules one after another.
Please add more details on your question and add your code.

Set Input Parameter in Custom Workflow Activity, Dynamic values are not populating?

On the saving of Case record I want to assign the case to respective Agent based on case type , sub type and Client/Account,
I have a Assignee field on Account form which I need to get the Agent's name to Assign the case.
I am creating a custom workflow activity for that, but while writing it I stuck how to fetch Case forms record on which I apply logic.
Please suggest what is the good approach, do I need to make a retrieve call to fetch these parameters or something else.
While setting the Custom Step Input Properties drop down fields are not populating to select the Dynamics Values.
Better to use plugin, as the documented/supported preimage is available in plugin steps + flexible.
You have to look for type, subtype, etc in target entity (incident in your case) or preimage if needed to apply logic.
If you still want to use workflow, go ahead & follow this article.
we can always read Pre image and Post image in the plug-in for various purpose. However, in workflow, we may sometimes want to read Pre Image for some purpose. Now we can also read Pre Images and Post Images in the workflow using Execution Context. It uses the same Plug-in Architecture and hence we can use it to read Pre Images and Post Images. However, this concept is not documented in the SDK so it might be unsupported.

Adding Extra fields on Joomla Registration Form

How to add extra fields in Joomla2.5 registration form? I am using profile plugin but i also want to change the order of the fields. Any Suggestion?
Copy the profile plugin and change it to do what you want, then install it and unpublish the old one.
You can add additional fields to the registration form by changing the database and a core component file.
First of all take a look of components\com_users\models\forms directory and there is a XML file called registration.xml. This is the file joomla creates the registration form fields. I hope you can understand this file and add what ever the necessary fields you want.
And after that check out your data base table called #__users and add the extra fields you want. (ex: if you want to add Telephone number add filed calld tp_no). And make sure to use the same name that you use in XML file "field name" for the database table column as well.
I imagine you are looking for something like this?
http://extensions.joomla.org/extensions/access-a-security/site-access/authentication/14303
Probably the safest solution in the short and long term. I've not used it but it looks like it does what you want and from an interface rather than changing hard code.
There is manual how do it. Turn on subtitles visit http://www.youtube.com/watch?v=a6xsKLiXF40

Drupal: Custom Content Type validation

I've created a custom content type with CCK.
If I need to add some custom code for validating fields of this content type's record form, where do I add the code and which functions are best for this task?
The easiest way would probably be hook_form_alter() and the #validation attribute on the form. You would of cause have to implement this in your own module.
The form api is what you use to validate, you'll be crafting your own validation function. I'm going to assume you are using D6
There's a less painful way:
http://drupal.org/project/validation_api
This module lets you make php code or regex for any given field.
Hope this helps.
To create your own module to implement form validation I suggest this method:
create a new module for content type field validation in drupal

Resources