Remove the spaces before <?php at the top
<?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)
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.
\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}
"}
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.
@Cronix, the problem was in the ChatModel after changing the $fillable, its fixed but. Still doesnt show off the data automatically.
What are you seeing in your browsers dev tools for what's being returned by the ajax call?
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.
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:
In the network section, check the response for the ajax call. There should be headers, Preview, Response, Cookies and Timing tabs.
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
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.
Done but now i see a blank page.
What does the response say
Literally, there is no page when I try to reach the home page. So I can't even see a chat tab.
ug, check the error log again.
error log isnt changed.
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)
response is {"test":"value"}
Ok, change the return to:
return ['html' => view('chats.message', compact('chat'))->render()];
Now run it again and check the console
{"html":""}
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?
chats.message :
<li class="list-group-item" style="word-wrap:break-word;">
<b>{{$chat->username}}</b>: {{$chat->chat}}
</li>
still get
{"html":""}
Does changing the return to what I last posted do anything?
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.
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;
No, i still get that. And yes, we are almost there lol, i need to eat something too, enjoy and thanks mate.
You still get what?
{"html":""}
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.