este mi RedirectiAutenticate
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class RedirectIfAuthenticated
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $guest)
{
$this->auth = $guest;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->check()) {
return redirect('/home');
}
return $next($request);
}
}
este es mi autenticate
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->to('auth/login');
}
}
if($request->path() == 'order-detail') return $next($request);
if(auth()->user()->type != 'admin'){
$message = 'Permiso denegado: Solo los administradores pueden entrar a esta sección';
return redirect()->route('home')->with('message', $message);
}
return $next($request);
}
}
esta es la controlador de el redireccionamiento de la pagina principal
cuando le descomento el midllguert me direcciona solo usurios admin y no normales y me quita el login como pagina principal.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Product;
class StoreController extends Controller
{
/*public function __construct()
{
$this->middleware('auth');
}*/
public function index()
{
$products = Product::all();
//dd($products);
return view('store.index', compact('products'));
}
public function show($slug)
{
$product = Product::where('slug', $slug)->first();
//dd($product);
return view('store.show', compact('product'));
}
}
cuando me logeo como usuario normal no me muestra la pagina de inisio osea la home
espero y puedan ayudarme soy nuevo en laravel
route........----
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::bind('product', function($slug){
return App\Product::where('slug', $slug)->first();
});
// Category dependency injection
Route::bind('category', function($category){
return App\Category::find($category);
});
// User dependency injection
Route::bind('user', function($user){
return App\User::find($user);
});
Route::get('/', [
'as' => 'home',
'uses' => 'StoreController@index'
]);
/*
Route::get('login', [
'as' => 'logo',
'uses' => 'StoreController@getLogin'
]);
*/
Route::get('product/{slug}', [
'as' => 'product-detail',
'uses' => 'StoreController@show'
]);
// Carrito -------------
Route::get('cart/show', [
'as' => 'cart-show',
'uses' => 'CartController@show'
]);
Route::get('cart/add/{product}', [
'as' => 'cart-add',
'uses' => 'CartController@add'
]);
Route::get('cart/delete/{product}',[
'as' => 'cart-delete',
'uses' => 'CartController@delete'
]);
Route::get('cart/trash', [
'as' => 'cart-trash',
'uses' => 'CartController@trash'
]);
Route::get('cart/update/{product}/{quantity}', [
'as' => 'cart-update',
'uses' => 'CartController@update'
]);
Route::get('order-detail', [
'middleware' => 'auth:user',
'as' => 'order-detail',
'uses' => 'CartController@orderDetail'
]);
// Authentication routes...
Route::get('auth/login', [
'as' => 'login-get',
'uses' => 'Auth\AuthController@getLogin'
]);
Route::post('auth/login', [
'as' => 'login-post',
'uses' => 'Auth\AuthController@postLogin'
]);
Route::get('auth/logout', [
'as' => 'logout',
'uses' => 'Auth\AuthController@getLogout'
]);
// Registration routes...
Route::get('auth/register', [
'as' => 'register-get',
'uses' => 'Auth\AuthController@getRegister'
]);
Route::post('auth/register', [
'as' => 'register-post',
'uses' => 'Auth\AuthController@postRegister'
]);
// Almacen..
Route::resource('almacen', 'AlmacenController');
Route::resource('productcreate', 'AlmacenController@create');
Route::post('altaproduc', [
'as' => 'almacen.product.store',
'uses' => 'AlmacenController@store'
]);
// Registra Empresa
Route::resource('empresa', 'EmpresaController');
Route::resource('empresacreate', 'EmpresaController@create');
Route::post('altaempresa', [
'as' => 'empresa.store',
'uses' => 'EmpresaController@store'
]);
// ***************************Categoria***********************************
Route::resource('categoria', 'CategoryController@index');
Route::resource('crear/categoria', 'CategoryController@create');
Route::resource('editar', 'CategoryController@edit');
//****************************perfil**************************************
Route::resource('perfil', 'PerfilController');
Route::resource('perfil/create', 'PerfilController@create');
Route::post('altaperfil', [
'as' => 'perfil.store',
'uses' => 'PerfilController@store'
]);
// Paypal
// Enviamos nuestro pedido a PayPal
Route::get('payment', array(
'as' => 'payment',
'uses' => 'PaypalController@postPayment',
));
// Después de realizar el pago Paypal redirecciona a esta ruta
Route::get('payment/status', array(
'as' => 'payment.status',
'uses' => 'PaypalController@getPaymentStatus',
));
// ADMIN -------------
Route::group(['namespace' => 'Admin', 'middleware' => ['auth'], 'prefix' => 'admin'], function()
{
Route::get('home', function(){
return view('admin.home');
});
Route::resource('category', 'CategoryController');
Route::resource('product', 'ProductController');
Route::resource('user', 'UserController');
Route::get('orders', [
'as' => 'admin.order.index',
'uses' => 'OrderController@index'
]);
Route::post('order/get-items', [
'as' => 'admin.order.getItems',
'uses' => 'OrderController@getItems'
]);
Route::get('order/{id}', [
'as' => 'admin.order.destroy',
'uses' => 'OrderController@destroy'
]);
});