I currently have a CRUD for the users. I'm using the edit and update path to modify the name and email data, but I need another edit path and an update path to change the user's password. I want to work them separately.
The question is how to generate those new routes of edit2 and update2. Try adding them to the user's driver and I do not create them.
I put the code of the user's driver in which I added the function of edit2 to create the route but it does not work:
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests\UserStoreRequest;
use App\Http\Requests\UserUpdateRequest;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class UserController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = User::orderBy('id', 'DESC')->paginate();
return view('admin.users.index', compact('users'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.users.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(UserStoreRequest $request)
{
//validacion
$user = User::create($request->all());
return redirect()->route('users.edit', $user->id)
->with('info', 'Usuario creado con exito');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$user = User::find($id);
return view('admin.users.show', compact('user'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$user = User::find($id);
return view('admin.users.edit', compact('user'));
}
public function edit2($id)
{
$user = User::find($id);
return view('admin.users.edit2', compact('user'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UserUpdateRequest $request, $id)
{
$user = User::find($id);
$user->name = $request->name;
$user->email = $request->email;
$user->save();
return redirect()->route('users.index')
->with('info','El usuario ha sido actualizado');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$user = User::find($id)->delete();
return back()->with('info', 'Eliminado correctamente');
}
}
I also place the web route code
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('inicio');
});
Route::get('instituto', function () {
return view('instituto');
})->name('instituto');
Route::redirect('news', 'blog');
Auth::routes();
//Web
Route::get('blog', 'Web\PageController@blog')->name('blog');
Route::get('entrada/{slug}', 'Web\PageController@post')->name('post');
Route::get('categoria/{slug}', 'Web\PageController@category')->name('category');
Route::get('etiqueta/{slug}', 'Web\PageController@tag')->name('tag');
//Admin
Route::resource('tags', 'Admin\TagController');
Route::resource('categories', 'Admin\CategoryController');
Route::resource('posts', 'Admin\PostController');
Route::resource('users', 'Admin\UserController');
EDIT1: Add the routes and they are recognized by the route: list
But I still get the message that it does not recognize the route, they were also added to the controller.