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

rushand's avatar

Header may not contain more than a single header, new line detected

I have a view to list all students, and a button(form) to make each student as a users button code

 <form action="{{route('make.user')}}" class="float-left" method="POST">
      <input type="hidden" value="{{$student->person->id}}" name="person_id">
      <button class="btn btn-outline-success mb-2 float-left" style="text-decoration:none"><i class="far fa-user-			 
         circle"></i> Make User</button>
 @csrf
</form>

Controller

    public function create(Request $request)
    {
        $person=Person::select('id','first_name','last_name','reg_id','email')->where('id',$request->person_id)->get()->first();
        $roles=Role::select('id','name')->get();
        return redirect (view('user.create',compact('roles','person')));
    }

Route

Route::group(['middleware' => 'admin'], function () {
    
    Route::resource('/users', 'AdminUsersController');
    
});

Error

ErrorException
Header may not contain more than a single header, new line detected
http://cms.test/make-user
0 likes
7 replies
MichalOravec's avatar

After creating your user redirect it to show or index method

public function create(Request $request)
{
    $person = Person::select('id','first_name','last_name','reg_id','email')->find($request->person_id);
    
    $roles = Role::select('id','name')->get();
    
    return view('user.create', compact('roles', 'person'));
}
1 like
rushand's avatar

Create method only loads the create form ,that form submits data to store method,,

MichalOravec's avatar

@rushand Yeah, I saw a store method.

But why do you have there this?

return redirect (view('user.create',compact('roles','person')));

It should be just

return view('user.create', compact('roles', 'person'));

Also this

<form action="{{route('make.user')}}" class="float-left" method="POST">

as

<form action="{{ route('users.store') }}" class="float-left" method="POST">

Because you use resource controllers

https://laravel.com/docs/7.x/controllers#resource-controllers

You mix many things together. Read again whole documentation.

rushand's avatar

Thanks for your quick responses , I have amended my code as following

Make User Button

                    <form action="{{route('users.create')}}" class="float-left" method="POST">
                      <input type="hidden" value="{{$student->person->id}}" name="person_id">
                      <button class="btn btn-outline-success mb-2 float-left" style="text-decoration:none"><i class="far fa-user-circle"></i> Make User</button>
                       @csrf
                    </form>

Since I needed to pass the person ID to the create method im using a post route, But create route is a get route by default..

What I have tried 1/ passed the make user button as a get route, and with the person id

<td class="data-fixed-columns ml-3 col-md-2"><a href="{{route('users.create',$student->person->id)}}">Make User</a> </td>

But I dont know how to retrive the $student->person->id insite the create method

MichalOravec's avatar
Level 75

@rushand Like this

route('users.create', ['person_id' => $student->person->id])
1 like

Please or to participate in this conversation.