0
votes

Logged in users can navigate to settings.blade.php and see their current email, password, name etc. From this form they should be able to update their email, password, name etc.

I have the form and it successfully pulls in user data from database. Now, when user updates (changes) a form field, such as 'name', I need the database to be updated accordingly. I just can't find what the form method="POST" action should be?

web.php

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

setting.blade.php

This page has a form so that users can update their name and email. Form POST method is missing because everything I try is not working
 <form method="POST" action="WHAT GOES HERE?" enctype="multipart/form-data">

SettingsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SettingsController extends Controller
{

    /**
     * Show the form for editing the specified resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function edit()
    {
        $user = auth()->user();
        return view('user_admin.settings', compact('user'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $request->validate([
            'first_name' => 'required',
            'last_name' => 'required',
            'email' => 'required',
        ]);

        $user = auth()->user();
        $user->first_name =  $request->get('first_name');
        $user->last_name =  $request->get('last_name');
        $user->email =  $request->get('email');
        $user->about_me =  $request->get('about_me');
        $user->save();
        return redirect('settings')->with('success', 'Settings updated!');
    }
}
2
I want to, but what's the action? <form method="POST" action="WHAT GOES HERE?" enctype="multipart/form-data">user11658543

2 Answers

1
votes

Simply call the route by name

<form method="POST" action="{{ route('settings_update') }}" enctype="multipart/form-data">
0
votes

When i started laravel i also faced that problem, post method naming was not working, then i try something like below code:

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

Then in blade file you can write like,

<form method="POST" action="{{ route('settings') }}" enctype="multipart/form-data">


Let me know if you need more help.