在MyAccountController[背包laravel]中添加配置文件信息



我考虑添加一个页面,以更改用户的配置文件:姓名、姓氏等。

Bug报告

文件:MyAccountController.php

函数:公共函数postAccountProfileForm(UpdateRequest$request(FormRequest,返回空

我做了什么:

DB:用户->配置文件

文件控制器:App\Http\Controllers\Auth\MyAccountController

namespace AppHttpControllersAuth;
use BackpackBaseappHttpControllersAuthMyAccountController as BaseMyAccountController;
use AppHttpRequestsAuthAccount_profileRequest as StoreRequest;
use AppHttpRequestsAuthAccount_profileRequest as UpdateRequest;
use Auth;
use AppModelsAuthAccount_profile;
class MyAccountController extends BaseMyAccountController
{
/**
* Show the user a form to change his personal information.
*/
public function getAccountProfileForm()
{
$user = Auth::user();
$this->data['title'] = trans('backpack::base.my_account');
$this->data['profile'] = Account_profile::getAccount_profilebyId($user->id);
return view('backpack::auth.account.update_profile', $this->data);
}
/**
* Save the modified personal information for a user.
*/
public function postAccountProfileForm(UpdateRequest $request)
{
//var_dump($request);
//die();
//$result = $this->guard()->user()->update($request->except(['_token']));
$result = Account_profile::getAccount_profilebyId($this->guard()->user()['id'])->update($request->except(['_token']));
if ($result) {
Alert::success(trans('backpack::base.account_updated'))->flash();
} else {
Alert::error(trans('backpack::base.error_saving'))->flash();
}
return redirect()->back();
}
}

文件请求:App\Http\Requests\Auth\Account_profileRequest

namespace AppHttpRequestsAuth;
use AppHttpRequestsRequest;
use IlluminateFoundationHttpFormRequest;
class Account_profileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
// only allow updates if the user is logged in
return backpack_auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
// 'name' => 'required|min:5|max:255'
'nome' => 'required|min:5|max:45',
'cognome' => 'required|min:5|max:45',
'sesso' => 'required|min:5|max:45',
'countrys_id' => 'required|numeric',
'regions_id' => 'required|numeric',
//'provinces_id' => 'required|numeric',
//'citys_id' => 'required|numeric',
'users_id' => 'required|numeric',
//'attivo' => 'required|boolean',
//'accetto_condizionigenerali' => 'required|boolean',
//'accetto_marketing' => 'required|boolean',
//'attivo_notifiche' => 'required|boolean'
//continue_13
];
}
/**
* Get the validation attributes that apply to the request.
*
* @return array
*/
public function attributes()
{
return [
//
];
}
/**
* Get the validation messages that apply to the request.
*
* @return array
*/
public function messages()
{
return [
//
];
}
}

文件模型:App\Models\Auth\Account_profile

namespace AppModelsAuth;
use IlluminateDatabaseEloquentModel;
use BackpackCRUDCrudTrait;
use AppModelsProfile;
class Account_profile extends Model
{
use CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
public static function getAccount_profilebyId($id)
{
return Profile::find($id);
}
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| SCOPES
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| ACCESORS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| MUTATORS
|--------------------------------------------------------------------------
*/
}

文件路径:路由\背包\自定义

// --------------------------
// Custom Backpack Routes
// --------------------------
// This route file is loaded automatically by BackpackBase.
// Routes you generate using BackpackGenerators will be placed here.
Route::group([
'prefix'     => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'namespace'  => 'AppHttpControllersAdmin',
], function () { // custom admin routes
}); // this should be the absolute last line of this file

Route::group(
[
'namespace'  => 'AppHttpControllersAuth',
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'prefix'     => config('backpack.base.route_prefix'),
],
function () {
// if not otherwise configured, setup the auth routes
if (config('backpack.base.setup_auth_routes')) {
// Authentication Routes...
}
// if not otherwise configured, setup the dashboard routes
if (config('backpack.base.setup_dashboard_routes')) {
Route::get('dashboard', 'AdminController@dashboard')->name('backpack.dashboard');
Route::get('/', 'AdminController@redirect')->name('backpack');
}
// if not otherwise configured, setup the "my account" routes
if (config('backpack.base.setup_my_account_routes')) {
Route::get('edit-account-profile', 'MyAccountController@getAccountProfileForm')->name('backpack.account.profile');
Route::post('edit-account-profile', 'MyAccountController@postAccountProfileForm');
}
});

文件刀片:resources\views\vendor\backage\base\auth\account\update_profile.Blade.php

@extends('backpack::layout')
@section('after_styles')
<style media="screen">
.backpack-profile-form .required::after {
content: ' *';
color: red;
}
</style>
@endsection
@section('header')
<section class="content-header">
<h1>
{{ trans('backpack::base.my_account') }}
</h1>
<ol class="breadcrumb">
<li>
<a href="{{ backpack_url() }}">{{ config('backpack.base.project_name') }}</a>
</li>
<li>
<a href="{{ route('backpack.account.info') }}">{{ trans('backpack::base.my_account') }}</a>
</li>
<li class="active">
{{ trans('backpack::base.update_account_info') }} Profile
</li>
</ol>
</section>
@endsection
@section('content')
<div class="row">
<div class="col-md-3">
@include('backpack::auth.account.sidemenu')
</div>
<div class="col-md-6">

<div class="box">
<div class="box-body backpack-profile-form">
{!! Form::open(array('route' => 'backpack.account.profile', 'method' => 'post')) !!}
<div class="form-group">
@php
$label = 'Nome';
$field = 'nome';
@endphp
{!! Form::label($field, $label, ['class' => 'required']) !!}
{!! Form::text($field, old($field) ? old($field) : $profile->$field, ['class' => 'form-control', 'required']) !!}
</div>
<div class="clearfix"></div>
<div class="form-group">
@php
$label = 'Cognome';
$field = 'cognome';
@endphp
{!! Form::label($field, $label, ['class' => 'required']) !!}
{!! Form::text($field, old($field) ? old($field) : $profile->$field, ['class' => 'form-control', 'required']) !!}
</div>
<div class="clearfix"></div>
<div class="form-group">
@php
$label = 'Sex';
$field = 'sesso';
@endphp
{!! Form::label($field, $label, ['class' => 'required']) !!}
{!! Form::select($field, array('M' => 'Male', 'F' => 'Female'), old($field) ? old($field) : $profile->$field, ['class' => 'form-control', 'required']) !!}
</div>
<div class="clearfix"></div>
<div class="box-footer">
@php
$field = 'id';
$label = '<span class="ladda-label"><i class="fa fa-save"></i>'.trans('backpack::base.save').'</span>';
@endphp
{!! Form::hidden($field, old($field) ? old($field) : $profile->$field) !!}
{!! Form::button($label, ['class' => 'btn btn-success', 'type' => 'submit']) !!}
<a href="{{ backpack_url() }}" class="btn btn-default"><span class="ladda-label">{{ trans('backpack::base.cancel') }}</span></a>
</div>
{!! Form::close() !!}
</div>
</div>

</div>
</div>
@endsection

我期望发生的事情:

我希望该表格经过验证

发生了什么:

当我提交时,请求返回给我空的

我已经尝试过修复它:

背包,Laravel,PHP,DB版本:

Laravel框架5.7.12"php":"^7.1.3"背包/备份管理器":"^1.4"背包/原油":"^3.4"backpack/langfilemanager":"^1.0"背包/日志管理器":"^2.3"背包/newscrud":"^2.1"背包/页面管理器":"^1.1"背包/权限管理器":"^3.12"背包/设置":"^2.1"barryvdh/laravel elfinder":"^0.4.1"fideliper/proxy":"^4.0"laravel/framework":"5.7.*","laravel/tinck":"^1.0","laravelcollective.html":"^5.7","mews/净化器":"^2.1","tymon/jwt auth":"^0.5.12">

你告诉背包不要设置身份验证路由,这样你就可以设置自己的身份验证路由了吗?

转到config/backpack/base.php并相应地更改setup_auth_routessetup_my_account_routes

如果你缓存了你的路线,不要忘记php artisan route:cache

最佳,Pedro

最新更新