Route :: group中的默认控制器用于路由?

时间:2018-02-20 10:21:11

标签: laravel laravel-5 laravel-routing

我想通过id显示一些用户数据。简单。

user/{id} - >从Controller的方法中获取数据。

我有这个:

Route::group(['prefix' => 'user/{id}', 'where' => ['id' => '[0-9]+']], function() {
       Route::get('delete', 'UserController@delete')->name('admin.access.user.delete-permanently');
       Route::get('restore', 'UserController@restore')->name('admin.access.user.restore');
       Route::get('mark/{status}', 'UserController@mark')->name('admin.access.user.mark')->where(['status' => '[0,1]']);
       Route::get('password/change', 'UserController@changePassword')->name('admin.access.user.change-password');
       Route::post('password/change', 'UserController@updatePassword')->name('admin.access.user.change-password');
});

如何将方法作为user/{id}的默认方式访问?

1 个答案:

答案 0 :(得分:2)

您可以在控制器中执行此操作

<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //Fetch and send the user to the "profile" blade file in the folder "resources/views/user"
        return view('user.profile', ['user' => User::findOrFail($id)]);
    }

    public function changePassword($id)
    {
        $user = User::findOrFail($id);
        return $user->update(
             'password' => bcrypt(123456)
        );
    }
}