Missing argument 2 for App\Http\Controllers\ProfileController::update()

Published 7 months ago by segun

i am trying to update my user details in the database but i am getting the above error here is my code on a gist file thanks in advance : https://gist.github.com/segun6060/22ce2bb94a918ba0b788187049da8bc8

Best Answer (As Selected By segun)
silverxjohn

Here is the snippet of your form

<form class="form-horizontal" role="form" method="POST" action="{{ url('/profile') }}">
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label for="name" class="col-md-4 control-label">User Name</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control" name="name" value="{{ Auth::user()->name}}" required autofocus>

                                @if ($errors->has('name'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

<!--Codes omitted  -->

In the <form class="form-horizontal" role="form" method="POST" action="{{ url('/profile') }}">

You must change it into:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/profile/' . Auth::user()->id) }}">

and from your routes/web.php change this line

Route::post('/profile', '[email protected]');

into

Route::post('/profile/{id}', '[email protected]');

Snapey
Snapey
7 months ago (652,495 XP)

Missing argument 2 ... obviously your id that you are not passing to the controller.

How is Laravel supposed to know which profile to update?

segun

@Snapey don't understand sir

Cronix
Cronix
7 months ago (160,520 XP)

Look at your update() method. It's expecting 2 parameters, the 2nd one being the users $id. That's what the error is referring to (missing argument 2)

Now look at your route. It's not accepting, or passing an ID back to the controller.

Your form also needs to post to /profile/id, where id is the id of the user you are updating.

segun

@Cronix once i put the id on the form on save the page is trying to direct me to profile/id and i got error saying the page does not exist

vipin93

why u just jumped learn how to update work in laravel, watch laravel from scratch 2017, and in your code if u use update your data so use patch method not post also u are not passing Id in your action url and route also, I think u asked so many questions which is very basic questions, and if given 1 day to laravel basic then I don't think so u asked these types of questions, stop and go learn basic of laravel

silverxjohn

Here is the snippet of your form

<form class="form-horizontal" role="form" method="POST" action="{{ url('/profile') }}">
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label for="name" class="col-md-4 control-label">User Name</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control" name="name" value="{{ Auth::user()->name}}" required autofocus>

                                @if ($errors->has('name'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

<!--Codes omitted  -->

In the <form class="form-horizontal" role="form" method="POST" action="{{ url('/profile') }}">

You must change it into:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/profile/' . Auth::user()->id) }}">

and from your routes/web.php change this line

Route::post('/profile', '[email protected]');

into

Route::post('/profile/{id}', '[email protected]');

segun

sometime if you watch the video you still have some question and you learn by asking i am sorry if i am not that good as you yet @vipin93 and you don't have to answer any of my question, there are millions of programmers out there that are ready to help, and i learned by asking and don't forget anything you already know will be simple as fuck in your eyes and be difficult in the eyes of those that does not know it and Laracast did this section for asking for help on what you don't know.

silverxjohn

Yow, we don't need to argue about nonsensical things here. There are times people forget to remember where they start. And sometimes, people becomes arrogant and thinks they know better. I once was like that. Well, everyone will sooner or later.

There are a lot of ways to learn. Some people learns from books, videos, etc while some learn by seeking others. No need to bring someone down just because "they're asking stupidly, simple things". Let's just help them and guide them to the right path.

Anyway, let's not sidetrack here, @segun have you fixed the problem?

vipin93

@segun what u said to me, same to u, and one thing u dont have read my answered fully , i have answered u are missing two things. and follow @silverxjohn answer and add one more thing. and one thing again same to u happy day

{{ method_field('PATCH') }}
Route::patch('/profile/{id}', '[email protected]');
segun

thanks everybody i have done it, before i did it without the id, but now i use the id aproach. @silverxjohn @vipin93 @Cronix @Snapey . thank you everybody, i have watch the video about one three weeks ago, in fact many video but i learn a lot by asking question some of the question i do asked i knew them but i asked to get other people opinion and my thanks especially go @silverxjohn God bless you and everybody including my friend @vipin93.

vipin93

@segum at the time of beginning when i start learning laravel, I'm also same as u I asked(even which very basic) every questions from this forum, many one suggested me I have to first learn basic but I never listen, because Why should I, if my problem will solve from this forum, so after many one suggested first learn basic so I decided to watch series laravel-5.** and @jeffery explain very well after,this when I faced any problem I try to implement own idea and it's worked after one or two attempt, sometimes if I was unable to solve then i asked.So want to say only this if u have basic then your 50-70% problem will solved by yourself. That's it I want to say u.

Please sign in or create an account to participate in this conversation.