What if you didnt?

|
a_anj 2020-11-02 19:34:27
natghi2010 2020-11-02 19:31:54
the best way is to send the data without leaving the page

Not using any ajax

a_anj 2020-11-02 19:35:52
DesolatorMagno 2020-11-02 19:26:32
Try changing the html to see how to put a default value.

Can u please elaborate

natghi2010 2020-11-02 19:36:33
a_anj 2020-11-02 19:34:27
Not using any ajax

https://laravel.com/docs/8.x/requests#old-input

a_anj 2020-11-02 19:41:27
natghi2010 2020-11-02 19:36:33
https://laravel.com/docs/8.x/requests#old-input

<textarea name=”description” id=”description” type=”text”> {{old(‘description’) }}</textarea>

not working for this

natghi2010 2020-11-02 19:42:06
a_anj 2020-11-02 19:41:27
<textarea name=”description” id=”description” type=”text”> {{old(‘description’) }}</textarea>

not working for this

show me the validation code

DesolatorMagno 2020-11-02 19:42:45
That’s the way to do it, fro creation at least.
a_anj 2020-11-02 19:43:09
$validator = Validator::make($request->all(), [
‘title’ => ‘required|string|regex:/^[a-zA-Z0-9 ]*$/|max:150’,
‘description’ => ‘required|string|max:250’,
]);

if ($validator->fails()) {

return redirect(‘release_notes/create’)->withErrors($validator)->withInput();
}

a_anj 2020-11-02 19:43:38
Description field
natghi2010 2020-11-02 19:45:14
a_anj 2020-11-02 19:43:09
$validator = Validator::make($request->all(), [
‘title’ => ‘required|string|regex:/^[a-zA-Z0-9 ]*$/|max:150’,
‘description’ => ‘required|string|max:250’,
]);

if ($validator->fails()) {

return redirect(‘release_notes/create’)->withErrors($validator)->withInput();
}

remove withErrors method

natghi2010 2020-11-02 19:45:26
and tell me if it works
natghi2010 2020-11-02 19:46:18
and if not above the validator declration
natghi2010 2020-11-02 19:46:31
put $request->flash();
natghi2010 2020-11-02 19:46:57
DesolatorMagno 2020-11-02 19:42:45
That’s the way to do it, fro creation at least.

and edit

DesolatorMagno 2020-11-02 19:49:19
Nope, for edit you also have to check the value of the model.
David P 2020-11-02 19:49:47
how to live my laravel project
natghi2010 2020-11-02 20:04:22
DesolatorMagno 2020-11-02 19:49:19
Nope, for edit you also have to check the value of the model.

Nope, it should be what i last entered

DesolatorMagno 2020-11-02 20:05:25
Dude, it need to check what have the model and what was the input, not in that order.
natghi2010 2020-11-02 20:06:36
DesolatorMagno 2020-11-02 20:05:25
Dude, it need to check what have the model and what was the input, not in that order.

oh i thought you meant the redirecting of request back to the form

DesolatorMagno 2020-11-02 20:06:53
Nope, i am talkin about the input, the way it is build.
DesolatorMagno 2020-11-02 20:07:35
a_anj 2020-11-02 19:41:27
<textarea name=”description” id=”description” type=”text”> {{old(‘description’) }}</textarea>

not working for this

That’s what was show at the moment, and is right, for creation only.

natghi2010 2020-11-02 20:09:20
DesolatorMagno 2020-11-02 20:07:35
That’s what was show at the moment, and is right, for creation only.

<textarea name=”description” id=”description” type=”text”> {{isset(old(‘description’)) ? old(‘description’) : $model->description}}</textarea>

natghi2010 2020-11-02 20:09:33
natghi2010 2020-11-02 20:09:20
<textarea name=”description” id=”description” type=”text”> {{isset(old(‘description’)) ? old(‘description’) : $model->description}}</textarea>

this is what i mean

natghi2010 2020-11-02 20:09:57
The user should have access to the last thing he wrote regardless of create/edit
DesolatorMagno 2020-11-02 20:35:45
And i didn’t say the contrary.
DesolatorMagno 2020-11-02 20:36:30
Just that if you make a input for only creation, the first example was more than enough.
DesolatorMagno 2020-11-02 20:37:27
I guess you don’t get error in a create form using $model->attribute.
natghi2010 2020-11-02 20:39:59
DesolatorMagno 2020-11-02 20:35:45
And i didn’t say the contrary.

I misunderstood

DesolatorMagno 2020-11-02 20:41:53
No problem, and a free tip

old(‘description’,$model->description)

natghi2010 2020-11-02 20:41:53
DesolatorMagno 2020-11-02 20:37:27
I guess you don’t get error in a create form using $model->attribute.

and $model->description ?? ”

natghi2010 2020-11-02 20:42:23
DesolatorMagno 2020-11-02 20:41:53
No problem, and a free tip

old(‘description’,$model->description)

oh i didnt know that one

DesolatorMagno 2020-11-02 20:42:25
laravel_discuss-57628.jpg
Old check if it exist, and accept a second parameter as a default value.
DesolatorMagno 2020-11-02 20:43:37
DesolatorMagno 2020-11-02 20:41:53
No problem, and a free tip

old(‘description’,$model->description)

That’s what i do for my form, and i use the same form for create and edit, the only thing that change is the form action url.

natghi2010 2020-11-02 20:45:45
DesolatorMagno 2020-11-02 20:43:37
That’s what i do for my form, and i use the same form for create and edit, the only thing that change is the form action url.

depending on how you update, i think you dont have to change the url even

natghi2010 2020-11-02 20:45:55
but thats a discussion for another day xD
DesolatorMagno 2020-11-02 20:48:44
Well, you have to change the method, and if we are talking about following rest routes, them you need to change the route.
natghi2010 2020-11-02 20:50:33
DesolatorMagno 2020-11-02 20:48:44
Well, you have to change the method, and if we are talking about following rest routes, them you need to change the route.

what if you didnt?

natghi2010 2020-11-02 20:52:15
DesolatorMagno 2020-11-02 20:48:44
Well, you have to change the method, and if we are talking about following rest routes, them you need to change the route.

public function store(){
$model = $request->the_id ? $model:findorfail($request->the_id) : new Model;
}

natghi2010 2020-11-02 20:53:56
natghi2010 2020-11-02 20:52:15
public function store(){
$model = $request->the_id ? $model:findorfail($request->the_id) : new Model;
}

this will be wrong if you have an update process that is not the same as your create process

DesolatorMagno 2020-11-02 20:54:57
But i do follow rest route, anything can be done in another way, you can make a delete action using get, you should? of course not.
DesolatorMagno 2020-11-02 20:55:45
And remeber that you have to take into account that there is a user out there, that could easily change any value or add any field into a form.
DesolatorMagno 2020-11-02 20:56:57
heck, you could make all the logic inside the form using isset($_POST )
natghi2010 2020-11-02 20:57:50
DesolatorMagno 2020-11-02 20:56:57
heck, you could make all the logic inside the form using isset($_POST )

I understand, but i like to cut corners whenever i can

DesolatorMagno 2020-11-02 20:58:57
For me is better following standard names, i was really happy when i learned about restfull routes and standard name for files, like, now i don’t spend hours thinking and remembering the name of the file for user creation
DesolatorMagno 2020-11-02 20:59:45
Putting everything inside the same method don’t make it better, easier or shorter.
DesolatorMagno 2020-11-02 21:01:21
When you create a user, the email need to be unique, when you edit it, it need to be unique but taking into account the user under edit, now, if you put it in the same place you need to put extra logic to know if is creation or edition (Just giving a simple example)
DesolatorMagno 2020-11-02 21:02:51
But in any case, is more about perspective than good and bad, i did my years of experimenting and i stay with what worked while trying new things.
natghi2010 2020-11-02 21:05:14
DesolatorMagno 2020-11-02 21:02:51
But in any case, is more about perspective than good and bad, i did my years of experimenting and i stay with what worked while trying new things.

I think the best practice as you said is keeping convention. Its not like nobody else thought of merging routes before. I use at my own risk.

DesolatorMagno 2020-11-02 21:06:58
Yeah, i do also think so, but didn’t wanted to keep the topic, i got work that i need to finish XD.
natghi2010 2020-11-02 21:08:00
DesolatorMagno 2020-11-02 21:06:58
Yeah, i do also think so, but didn’t wanted to keep the topic, i got work that i need to finish XD.

whats amazing is how i find the time for this discussions.

2020-11-02 21:11:18
https://youtu.be/P0szX_aDwR8

E-commerce website with multi vendor support shopping, store, admin dashboard part -1YouTube
|