Laravel Login redirects to blank page

Published 1 year ago by afonte15

PLEASE SEE UPDATED QUESTION WITH ALL CODE IN PROPER FORMAT!

https://laracasts.com/discuss/channels/laravel/laravel-login-redirects-to-blank-page-1

Hello Everyone,

I have been stuck with Laravel redirecting after login. The connection works and after I login it redirects to a blank page but if I change the url path I can access the different web pages. Any assistance would be highly appreciated! I am using LDAP to connect and it is working. On my AuthController I have the protected $redirectTo paths set. See picture below. enter image description here

Please let me know if there is any other code I should provide.

Thank you!!!

' ' '<?

namespace App\Http\Middleware;

use Closure; use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated {

protected $auth; /**

  • Handle an incoming request.

  • @param \Illuminate\Http\Request $request

  • @param \Closure $next

  • @param string|null $guard

  • @return mixed */ public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { return redirect('/computers/create'); }

    return $next($request); } } ' ' '

Routes.php

'''Route::group(['middleware' => ['web']], function () {

Route::auth(); Route::get('login', '[email protected]'); Route::post('login', '[email protected]_password'); Route::patch('computers/{inventories}', '[email protected]'); Route::get('computers/search', '[email protected]'); Route::resource('computers', 'InventoriesController'); }); Route::get('/home', '[email protected]'); ' ' '

LoginController.php

' ' '<?php namespace App\Http\Controllers; /**

  • @class Login / use App\User; use Illuminate\Http\Request; class Login extends Controller { /*

    • Show the application dashboard to the user.
    • @return Response */ public function index() { return view('auth.login'); } public function check_password(Request $req)

    { //die('has to stop here'); $user = User::check_password($req); //var_dump($user); die; if ($user) {

         return redirect('/computers/create');
     }
     else
    

    {

         return redirect('login')->with('message', 'Login Failed');
     }
    

    } } ' ' '

AuthController.php

' ' '<?php

namespace App\Http\Controllers\Auth;

use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; class AuthController extends Controller { /* |-------------------------------------------------------------------------- | Registration & Login Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users, as well as the | authentication of existing users. By default, this controller uses | a simple trait to add these behaviors. Why don't you explore it? | / use AuthenticatesAndRegistersUsers, ThrottlesLogins; /* * Where to redirect users after login / registration. * * @var string */

protected $redirectTo = '/computers/create';
protected $redirectAfterLogout = '/login';
/**
 * Create a new authentication controller instance.
 *
 * @return void
 */


public function __construct()
{
    //$this->auth = $auth;
    //$this->registrar = $registrar;

    $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
//Using Ldap

// protected function validator(array $data) // { // return Validator::make($data, [ // 'name' => 'required|max:255', // 'email' => 'required|email|max:255|unique:users', // 'password' => 'required|min:6|confirmed', // ]); //} /** * Create a new user instance after a valid registration. * * @param array $data * @return User */ //Removed b/c LDAP is being usedcd // protected function create(array $data) // { // return User::create([ // 'name' => $data['name'], // 'email' => $data['email'], // 'password' => bcrypt($data['password']), // ]); // } } ' ' '

InventoriesController.php

' ' '<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request; use DB; use App\Inventory; use App\Http\Requests\InventoryRequest; class InventoriesController extends Controller { public function __construct() { //$this->middleware('auth'); //does not allow users to login, redirects back to login when using LDAP credentials

}
public function index(Request $request)
{
    $location = $request->input("building");
    if ($location != null) {
        $inventories = Inventory::where('building', $location)->get();
    }  else {
        $inventories = Inventory::all();
    }
    return view('computers.index', compact('inventories'));
}
public function show($inventories)
{
    $inventories = Inventory::findOrFail($inventories);
    return view::make('computers.show')
        ->with('inventory', $inventories);
}
public function create(){
    //flash('Hello World', 'This is the message');
    return view('computers.create');
}
/**
 * Store a newly created resource in storage.
 *
 * @param  inventory  $request
 * @return Response
 *
 */
public function store(InventoryRequest $request)
{
       Inventory::create($request->all());
    flash('Success!', 'Inventory Successfully Updated!');

// // return redirect()->back(); //temporary return back(); } public function edit($inventories) { $inventories = Inventory::findOrFail($inventories); return view('computers.edit', compact('inventories')); } public function update(InventoryRequest $request, Inventory $inventories){ $inventories->update($request->all()); flash('Success!', 'Inventory Successfully Updated!'); return back(); } public function search() { $search = \Request::get('q'); //<-- we use global request to get the param of URI // $search = Input::get('search'); $inventories = Inventory::where('lastName','LIKE','%'.$search.'%') -> orwhere('firstName', 'LIKE','%'.$search.'%' ) -> orwhere('department', 'LIKE','%'.$search.'%' ) -> orwhere('building', 'LIKE','%'.$search.'%' ) -> orwhere('room', 'LIKE','%'.$search.'%' ) -> orwhere('manufacturer', 'LIKE','%'.$search.'%' ) -> orwhere('device', 'LIKE','%'.$search.'%' ) -> orwhere('model', 'LIKE','%'.$search.'%' ) -> orwhere('tag', 'LIKE','%'.$search.'%' ) -> orwhere('macAddress', 'LIKE','%'.$search.'%' ) -> orwhere('status', 'LIKE','%'.$search.'%' ) -> orwhere('comments', 'LIKE','%'.$search.'%' ) ->get(); return view('computers.search',compact('inventories')); } } ' ' '

samalapsy

Please can you paste your login code and your route?

Thanks

zsoltgyure

Hi, Maybe you forgot to set up a route, or if you didn't, you maybe forgot to put "return" keyword before your view() function. These are the common mistakes. Anyways we need to see your code.

zsoltgyure

What is in your computers/create.blade.php ?

Please sign in or create an account to participate in this conversation.