I have a problem with Laravel 5.2.
At the moment of authenticating the user and redirecting to the home or login depending, the messages that I create by Session::flash()
do not appear and on the home page when I try to show the name of the authenticated user using Auth::user()->show_name
I get an error.
I tried inside the controller that I created for the authentication and the values show them to me, but when I redirect to the home or to the login it does not show anything.
What error do I have or what do I see in the view or in the drivers?
Model :: User.php
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected $table = 'users_panel';
protected $fillable = [
'show_name',
'user',
'password',
];
protected $hidden = [
'password', 'is_admin',
];
}
routes.php
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('/orders', function () {
return view('tp-admin/index', ['class' => 'login contrast-background']);
});
Route::resource('log', 'LogController');
Route::resource('logout', 'LogController@logout');
Route::get('/orders-panel/home', 'HomeController@index');
Route::group(['middleware' => ['web']], function () {
});
LogController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use Session;
use Redirect;
use App\User;
use App\Http\Requests;
class LogController extends Controller
{
public function store(Request $request)
{
if($this->LogIn(['user' => $request['user'], 'password' => $request['password']], $request['remember_me'])){
Session::flash('message', 'Sirve');
//return Redirect::to('/orders-panel/home');
//-------------------Aqui Mostre que si estaban llegando los datos a los mensaje
if(Auth::check()):
echo Auth::user()->show_name;
echo '<br>';
echo Session::get('message');
endif;
}else{
Session::flash('message', 'Error');
//-------------------Aqui Mostre que si estaban llegando los datos a los mensaje
echo Session::get('message');
//return Redirect::to('/orders');
}
}
public function logout()
{
Auth::logout();
return Redirect::to('/orders');
}
private function LogIn(array $credentials = [], $remember = false)
{
if ($this->ValidCredentials($credentials)) {
if($this->ValidUser($credentials)){
Auth::login($this->ValidUser($credentials), $this->ValidRemember($remember));
return true;
}
}
return false;
}
private function ValidCredentials($credentials)
{
if (($credentials['password'] != '') and ($credentials['user'] != '')) {
return true;
}
}
private function ValidRemember($remember = false)
{
if(isset($remember)){
return true;
}
}
private function ValidUser($credentials)
{
return User::where('user', $credentials['user'])
->where('password', md5($credentials['password']))
->first();
}
}
HomeController.php
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function __construct()
{
}
public function index()
{
return view('tp-admin/home');
}
}
home.blade.php
@extends('layouts.app')
@section('content')
<p>
Aqui deveria salir el mensaje de Session::
@if(Session::has('message'))
{{Session::get('message')}}
@endif
</p>
{!! trans('panel.welcome') !!}
<p>
<a href="/logout">LogOut</a>
</p>
@endsection