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

Cronix's avatar

Remove the spaces before <?php at the top

uhbc's avatar
Level 1
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use App\Http\Controllers\Auth;
use App\ChatModel;

class ChatController extends Controller
{

Still 500 (Internal Server Error)

Cronix's avatar

Blank line after <?php like you originally had. Make sure the php open tag is the very first line.

<?php

namespace App\Http\Controllers;

Check the error log again if that doesn't fix it.

uhbc's avatar
Level 1
\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#65 /var/www/0/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#66 /var/www/0/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#67 /var/www/0/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#68 /var/www/0/public_html/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#69 {main}
"} 
Cronix's avatar

That doesn't really tell me much because you showed lines #65-#69 of the error. Show the first 10 or so lines, not the last lines.

uhbc's avatar
Level 1

@Cronix, the problem was in the ChatModel after changing the $fillable, its fixed but. Still doesnt show off the data automatically.

Cronix's avatar

What are you seeing in your browsers dev tools for what's being returned by the ajax call?

uhbc's avatar
Level 1

Like in every chat site, you don't have to refresh the page because the things you write are automatically loading in the page, you are not being had to f5, but in my case, I have to refresh the page to see what people have typed.

uhbc's avatar
Level 1

There is nothing in the Console/Chrome, and in the Network section:

General:
Request URL: http://35.196.31.255/chat
Request Method: POST
Status Code: 200 OK
Remote Address: 35.196.31.255:80
Referrer Policy: no-referrer-when-downgrade

Form Data:
cett: asdfasdfasdf
_tokenin5cIFkBOSF13SfVwqLiDH9PQnNHdzBr450Szols: 
Cronix's avatar

In the network section, check the response for the ajax call. There should be headers, Preview, Response, Cookies and Timing tabs.

uhbc's avatar
Level 1

In here: http://prntscr.com/j1jcwb

Headers:
General:
Request URL: http://35.196.31.255/chat
Request Method: POST
Status Code: 200 OK
Remote Address: 35.196.31.255:80
Referrer Policy: no-referrer-when-downgrade

Form Data:
cett: asdfasdfasdf
_tokenin5cIFkBOSF13SfVwqLiDH9PQnNHdzBr450Szols: 

Response:
This request has no response data available

Cookies:
http://prntscr.com/j1jdb7
Cronix's avatar
Response:
This request has no response data available

Strange. In the chat method in your controller, are you still returning the view?

$view = view()->make('chats.message', compact('chat'));
return $view->render();

Maybe try changing it to just

return view('chats.message', compact('chat'));

Then again, check the response in the browser tools.

uhbc's avatar
Level 1

Done but now i see a blank page.

uhbc's avatar
Level 1

Literally, there is no page when I try to reach the home page. So I can't even see a chat tab.

uhbc's avatar
Level 1

error log isnt changed.

Cronix's avatar

OK, change this return view('chats.message', compact('chat')); to return ['test' => 'value'];

Add this to your ajax call in the success method:

success: function (response) {
    console.log(response);
    $('#chat > .list-group').append(response);
}

Try it again and check the console of the browser when you submit (assuming it gets that far)

uhbc's avatar
Level 1

response is {"test":"value"}

Cronix's avatar

Ok, change the return to:

return ['html' => view('chats.message', compact('chat'))->render()];

Now run it again and check the console

Cronix's avatar
return response([
    'html' => view('chats.message', compact('chat'))->render()
]);

? This is hard to troubleshoot without all this on my computer

Also, what does your chats.message view look like?

uhbc's avatar
Level 1

chats.message :

<li class="list-group-item" style="word-wrap:break-word;">
    <b>{{$chat->username}}</b>: {{$chat->chat}}
</li>

still get {"html":""}

Cronix's avatar

Does changing the return to what I last posted do anything?

Cronix's avatar

Well, we're 99% there. This is annoying lol.

I have to go eat but I'll try to check back later. It's getting late.

Cronix's avatar

In the controller, right after you save the chat, add return $chat

$chat = ChatModel::create([
            'chat' => $request->cett,
            'userid' => \Auth::user()->id,
            'username' => \Auth::user()->name // do you really need to store the user's name as well as the ID?
]);

return $chat;
uhbc's avatar
Level 1

No, i still get that. And yes, we are almost there lol, i need to eat something too, enjoy and thanks mate.

Cronix's avatar

You shouldn't if you put the return $chat; where I showed. Immediately after you create $chat, return $chat.

Please or to participate in this conversation.