I have this form here
<form action="{{ route('usuario.update') }}" method="post">
<input id="token" type="hidden" value="{{ csrf_token() }}" name="_token"/>
<input type="hidden" value="{{ $usuario }}" name="user">
<input type="hidden" value="{{ $usuario->id }}" name="id">
@if( \Auth::id() == $usuario->id )
<input type="hidden" value="S" name="sn_atual">
@else
<input type="hidden" value="N" name="sn_atual">
@endif
<div class="form-group col-lg-10 {{ $errors->has('nome') ? ' has-error' : '' }}">
<label for="nome">Nome</label>
<input id="nome" name="nome" class="form-control " required value="{{ $usuario->name }}"/>
@if ($errors->has('nome'))
<span class="help-block">
<strong>{{ $errors->first('nome') }}</strong>
</span>
@endif
</div>
<div class="form-group col-lg-5 {{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email">E-mail</label>
<input id="email" name="email" type="email" class="form-control" required required value="{{ $usuario->email }}"/>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class="row"></div>
<div class="form-group col-lg-3">
<label>
<input type="checkbox" value="S" name="sn_ativo" checked >Ativo
</label>
</div>
@if( Auth::id() == $usuario->id )
<div class="form-group col-lg-3 {{ $errors->has('pwd') ? ' has-error' : '' }}">
<input name="password" id="senha" class="form-control" placeholder="Senha" required />
@if ($errors->has('pwd'))
<span class="help-block">
<strong>{{ $errors->first('pwd') }}</strong>
</span>
@endif
</div>
<div class="form-group col-lg-3">
<input name="password1" id="senha" class="form-control" placeholder="Repita a Senha" required />
</div>
@else
<div class="form-group col-lg-3">
<input type="hidden" name="password" id="senha" class="form-control" placeholder="Senha" required value="12345678"/>
</div>
<div class="form-group col-lg-3">
<input type="hidden" name="password1" id="senha" class="form-control" placeholder="Repita a Senha" required value="12345678"/>
</div>
@endif
<div class="row"></div>
<div class="col-lg-3">
<button type="submit" class="btn btn-success btn-salvar">Salvar</button>
<a class="btn btn-default btn-cancelar">Voltar</a>
</div>
I have my route within the group:
Route::group(['as' => 'usuario.', 'prefix' => 'usuario'], function (){
Route::post('edit',['as' => 'edit', 'uses' => 'UsuarioController@edit']);
Route::get('edit',['as' => 'edit', 'uses' => 'UsuarioController@edit']);
});
Within the group, my route generates this way in the url:
http://meuapp/usuario/edit
When trying to change the back returns using get, but not all variables return with successfully, for example:
The user object, gives problem
Trying to get property of non-object (View:
How do I know?
I think it's because of this line here:
at PhpEngine-> evaluatePath ('D: \ wamp \ www \ restaurant \ storage \ framework \ views / 40b090229a7702d4db310979456e280426f93706.php', array ('__ env' => object (Factory), 'app' => object (Application) 'errors' = > object (ViewErrorBag), 'user' = > null)) in CompilerEngine.php line
User comes null when back
'usuario' => null
Any ideas?
[EDIT 1]
My controller is trying to do this:
public function update( Request $request ){
$nome = $request->get('nome');
$email = $request->get('email');
$password = $request->get('password');
$password1 = $request->get('password1');
$ativo = $request->get('sn_ativo');
$senha = $request->get('sn_atual');
$id = $request->get('id');
$usuario = User::find( $id );
if( !is_null( $ativo ) ){
$ativo = 'S';
}else{
$ativo = 'N';
}
$validator = Validator::make(
[ 'nome' => $nome
,'pwd' => $password
,'pwd1' => $password1
,'email' => $email
],
[
'nome' => 'required|min:6'
,'pwd' => 'required|min:8:confirmed'
,'pwd1' => 'required|min:8'
,'email' => 'required'
],
[
'required' => ':attribute é obrigatório'
,'nome.min' => ':attribute tem que no mínimo 6 caracteres'
,'pwd.min' => ':attribute tem que no mínimo 8 caracteres'
]
);
if( $validator->fails() ){
return redirect()->back()->withErrors( $validator )->withInput()->with( 'usuario', $usuario );
}else{
$usuario->name = $nome;
$usuario->email = $email;
$usuario->password = Hash::make( $password );
$usuario->sn_ativo = $ativo;
$usuario->sn_senha_atual = $senha;
if( $usuario->save() ){
//return response()->json( array( 'success' => 1 ) );
return redirect()->route('usuario.index');
}else{
//return response()->json( array( 'success' => 0 ) );
return redirect()->back()->with( 'exception', 'Um problema ocorreu' );
}
//return redirect()->route('emp.index');
}
}