user11658543
user11658543

Reputation:

Laravel - User edit form not linking to controller

UPDATE: I think the issue is definitely with the form method POST. I've reworded my question and given full code in a new thread here stackoverflow.com/questions/58043675/form-method-post-action

I'm creating a page for users to update their settings (settings.blade.php), it's stored inside a user_admin folder, so the correct path is user_admin/settings.blade.php.

Here is my SettingsController.php

public function edit()

{
 $user = auth()->user();
return view('user_admin.settings', compact('user'));
}

And here is how I am trying to link to it;

<form method="POST" action="{{ route('user_admin/settings.edit', $settings->id)}}" enctype="multipart/form-data">
@csrf

The error I get is

'Undefined variable'

I've also tried {{ route('settings') }}, but I get error:

'Route [settings] not defined.'

Here the form input in my form that users edit:

 <label for="first_name" class="col-md-4 col-form-label text-md-right">{{ __('First Name') }}</label>

Plus, in the user dashboard, I have a link to 'settings' which is {{ route('user_admin/settings.edit')}}. The trouble, the dashboard won't open because of the error

Route [user_admin/settings.edit] not defined

Here are my Routes:

Route::get('settings', 'SettingsController@edit');
Route::post('settings/update', 'SettingsController@update');

END

Everything below this line is my reply to specific comments.

@Rashed Hasan

|        | POST      | password/email             | password.email   | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest                                       |
|        | GET|HEAD  | password/reset             | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest                                       |
|        | POST      | password/reset             | password.update  | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest                                       |
|        | GET|HEAD  | password/reset/{token}     | password.reset   | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest                                       |
|        | GET|HEAD  | pricing                    |                  | Closure                                                                | web                                             |
|        | GET|HEAD  | register                   | register         | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest                                       |
|        | POST      | register                   |                  | App\Http\Controllers\Auth\RegisterController@register                  | web,guest                                       |
|        | GET|HEAD  | settings                   |                  | App\Http\Controllers\SettingsController@edit                           | web                                             |
|        | POST      | settings/update            |                  | App\Http\Controllers\SettingsController@update                         | web                                             |
|        | GET|HEAD  | uli_groups_created         |                  | Closure                                                                | web                                             |
|        | GET|HEAD  | uli_groups_joined          |                  | Closure                                                                | web                                             |
|        | GET|HEAD  | upload_profile_image       |                  | Closure                                                                | web                                             |
|        | GET|HEAD  | welcome                    |                  | Closure                                                                | web                                             |
+--------+-----------+----------------------------+------------------+------------------------------------------------------------------------+-------------------------------------------------+

Upvotes: 0

Views: 136

Answers (2)

user11658543
user11658543

Reputation:

correct link was {{ route('settings.update') }}

The problem was caused due to a previous change to user name, we added user first_name and last_name to the sign up form, which meant that 'name' was not being recognised. After updating links to point to first_name and last_name, and adding above link, it all worked fine.

Upvotes: 0

Ridham
Ridham

Reputation: 86

First of all you should give name to each and every route like,

Route::get('settings', 'SettingsController@edit')->name('settings');
Route::post('settings/update', 'SettingsController@update')->name('settings_update');

This way you can uniquely identify each and every route

Now what you did in below code:

<form
  method="POST"
  action="{{ route('user_admin/settings.edit', $settings->id)}}"
  enctype="multipart/form-data"
>

You have passed an ID with the route but there is not any route defined with parameter, refer below code: Route:

Route::get('user/{id}/profile','ProfileController@profile')->name('profile');

Inside blade file:

<form 
  method="POST" 
  action="{{route('profile', ['id' => 1])}}"
  enctype="multipart/form-data"
>

So basically in route() function, first argument should route name and a second argument you can pass array with list of parameters that you have defined in route file, with specific route to be used.

Let me know if you still need my help.

Upvotes: 2

Related Questions