Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sanjayacloud's avatar

"Header may not contain more than a single header, new line detected" After user is login

Hi,

I have above error after user login my admin login controller. My controller like below.

<?php
namespace App\Http\Controllers\Partner\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
  

    use AuthenticatesUsers;
    
    public function showLoginForm()
    {
        return view('partner.auth.login');
    }

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function redirectTo()
    {
        if (Auth::user()->role == '0') {
            return redirect('/');
        } elseif (Auth::user()->role == '1' && Auth::user()->status == '1'){
            return redirect('admin/experience');
        }elseif (Auth::user()->role == '5'){
            return redirect('admin/dashboard');
        }
    }
}

Can anyone help me for resolve this error?

0 likes
12 replies
munazzil's avatar

I think error in admin.auth.login because this error came you have used @extends() or @yield(),It may caused this problem check the blade.php files.Else check your web.php sometimes any typing error occurred.

devfrey's avatar

Make sure you don't have any whitespace before PHP's opening tags (<?php) in any PHP file.

sanjayacloud's avatar

@MUNAZZIL - This my blade file. There are know find any issue. Can you check it?

@extends('layouts.site')
@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">{{ __('Admin Login') }}</div>

                    <div class="card-body">
                        <form method="POST" action="{{ route('admin.login') }}">
                            @csrf

                            <div class="form-group row">
                                <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                                <div class="col-md-6">
                                    <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>

                                    @if ($errors->has('email'))
                                        <span class="invalid-feedback" role="alert">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                                <div class="col-md-6">
                                    <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>

                                    @if ($errors->has('password'))
                                        <span class="invalid-feedback" role="alert">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>

                            <div class="form-group row">
                                <div class="col-md-6 offset-md-4">
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>

                                        <label class="form-check-label" for="remember">
                                            {{ __('Remember Me') }}
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row mb-0">
                                <div class="col-md-8 offset-md-4">
                                    <button type="submit" class="btn btn-primary">
                                        {{ __('Login') }}
                                    </button>

                                    @if (Route::has('password.request'))
                                        <a class="btn btn-link" href="{{ route('password.request') }}">
                                            {{ __('Forgot Your Password?') }}
                                        </a>
                                    @endif
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

sanjayacloud's avatar

@DEVFREY - II have check my files there aren't any white space found. Can you help me. please check reply. I have added my blade file.

munazzil's avatar

In your @extends('layouts.site') there are another path also as like this in your view```@extends('layouts.app')``. Post your layouts.site as well.

sanjayacloud's avatar

@MUNAZZIL - This is my layout.site file

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- CSRF Token -->
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>{{ config('app.name', 'Laravel') }}</title>

        <!-- Fonts -->
        <link rel="dns-prefetch" href="//fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

        <!-- Styles -->
        <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    </head>
    <body>
        <div id="app">
            <nav class="navbar navbar-expand-md navbar-light navbar-laravel">
                <div class="container">
                    <a class="navbar-brand" href="{{ url('/') }}">
                        {{ config('app.name', 'Laravel') }}
                    </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                        <span class="navbar-toggler-icon"></span>
                    </button>

                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <!-- Left Side Of Navbar -->
                        <ul class="navbar-nav mr-auto">

                        </ul>

                        <!-- Right Side Of Navbar -->
                        <ul class="navbar-nav ml-auto">
                            <!-- Authentication Links -->
                            @guest
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @if (Route::has('register'))
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                            </li>
                            @endif
                            @else
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }} <span class="caret"></span>
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                               document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                            @endguest
                        </ul>
                    </div>
                </div>
            </nav>
            <main class="py-4">
                @yield('content')
            </main>
        </div>
        <!-- Scripts -->
        <script>
            var base = '{{url(' / ') . ' / '}}';
        </script>
        <script src="{{ asset('js/app.js') }}" defer></script>
        <script src="{{asset('assets/frontend/js/jquery.sticky.js')}}"></script>
    </body>
</html>


assem_saad's avatar

@sanjayacloud no use redirect after return if (Auth::user()->role == '0') { return route('name route'); } elseif (Auth::user()->role == '1' && Auth::user()->status == '1'){ return route('name route');; }elseif (Auth::user()->role == '5'){ return route('name route');

Snapey's avatar

Its usually whitespace before <?php or you have tried to close a php file with ?> which you should never do.

This error WILL NOT be related to any BLADE file

sanjayacloud's avatar

@SNAPEY - I got point where exactly error is coming. When i add below code to my LoginController to redirect to specific paths based on user role. Once I comment that this error doesn't come. See below my Login Controller.

<?php

namespace App\Http\Controllers\Admin\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class AdminLoginController extends Controller {
    /*
      |--------------------------------------------------------------------------
      | Login Controller
      |--------------------------------------------------------------------------
      |
      | This controller handles authenticating users for the application and
      | redirecting them to your home screen. The controller uses a trait
      | to conveniently provide its functionality to your applications.
      |
     */

use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
   // protected $redirectTo = 'admin/product';

    /**
     * Show the application's login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function showLoginForm() {
        return view('admin.auth.login');
    }

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct() {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Log the user out of the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request) {
        $this->guard()->logout();
        $request->session()->invalidate();
        return $this->loggedOut($request) ?: redirect('admin.auth.login');
    }

//    public function redirectTo()
//    {
//        if (auth()->user()->role == '0') {
//            return redirect('/');
//        } elseif (auth()->user()->role == '1' && auth()->user()->status == '1'){
//            return redirect('admin/experience');
//        }elseif (auth()->user()->role == '5'){
//            return redirect('admin/dashboard');
//        }
//    }


}

Snapey's avatar

So the problem is in one of those redirected routes...

sanjayacloud's avatar

@SNAPEY - But. If I directly access these routs, It's work. why for only this redirection?

Snapey's avatar

Thinking about it more, I think your redirectTo function is expecting to return a string, not a redirect object.

Change all returns like

return 'admin/experience';
2 likes

Please or to participate in this conversation.