首页 > 代码库 > 最简单的增删改查

最简单的增删改查

<?phpnamespace App\Http\Controllers\Admin;use App\Models\AdminUser;use App\Http\Requests\Admin\AdminuserRequest;class AdminusersController extends Controller{    public function getIndex()    {        $users = AdminUser::where(‘role‘, ‘adminer‘)            ->where(‘id‘, ‘!=‘, 1)            ->paginate(8);        return view(‘admin.admin_users.index‘, compact(‘users‘));    }    public function getData(AdminUser $users)    {        $users->mergeAttributesOld();        return view(‘admin.admin_users.edit‘, compact(‘users‘));    }    public function getEdit($id)    {        $users = AdminUser::findOrFail($id);        return view(‘admin.admin_users.edit‘, compact(‘users‘));    }    public function postStore(AdminuserRequest $request)    {        $data = $request->getData();        $data[‘role‘] = ‘adminer‘;        AdminUser::create($data);        return redirect()->action(‘Admin\AdminusersController@getIndex‘);    }    public function postUpdate(AdminuserRequest $request, $id)    {        $data = $request->getData();        $users = AdminUser::findOrFail($id);        $users->update($data);        return redirect()->action(‘Admin\AdminusersController@getIndex‘);    }    public function deleteAdminUser($id)    {        AdminUser::findOrFail($id)->delete();        return redirect()->action(‘Admin\AdminusersController@getIndex‘);    }}

 

最简单的增删改查