uhbc

uhbc

Member Since 1 Year Ago

Experience Points 1,460
Experience Level 1

3,540 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

06 Jun
1 week ago

uhbc left a reply on How To Return Multiple Variables To A View And Use Them

Thank you @sergiu17 @cronix I decided to create a new view. Things are less complicated now.

05 Jun
1 week ago

uhbc started a new conversation How To Return Multiple Variables And Use Them

How do I use 2 variables that are returned by different controllers to the same view. Here are the controllers:

public function function1(){
      // https://site.com/home
      $res = \DB::table("somedb")->get();
      return view('home', ["variable1"=>$res]);
    }
    public function function2($id){
      // https://sitem.com/home/1
      $res = \DB::table("somedb")->where("id", $id)->get();
      return view('home', ["variable2"=>$res]);
    }

And here is the home.blade.php


<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>ID</th>
          <th>Name</th>
          <th>Process</th>
        </tr>
      </thead>

      @if(isset($variable1))
      <tbody>
        @foreach($variable1 as $row)
        <tr>
          <td>{{$row->id}}</td>
          <td>{{$row->name}}</td>
          <td>[a button to edit this row etc..]</td>
        </tr>
        @endforeach
    </tbody>
    @else
      <tbody>
        @foreach($variable2 as $row)
        <tr>
          <td>{{$row->id}}</td>
          <td><input type="text" name="name" value="{{$row->name}}"></td>
          <td>[a button to submit etc..]</td>
        </tr>
        @endforeach
      </tbody>
    @endif
    </table>
  </body>
</html>

When I'm trying to this, giving me an error of "Undefined variable: variable2 (View: .../home.blade.php)"

What should I do

06 Jul
11 months ago

uhbc left a reply on Set Variable For JSON.

Worked, thank you.

uhbc left a reply on Set Variable For JSON.

It's trying to look for a data called 'variable' from JSON.

i want something like;

var variable = 'a1';
console.log( e[0].variable  );

So, i wanna see;

"1"

uhbc left a reply on Set Variable For JSON.

I think i accidentally used a wrong url, fixed it anyways. Here is how it looks like:

[
{
act: null,
id: "1",
a1: "1",
a2: "0",
a3: "0",
u1: "ax-1",
u2: "ax-2",
u3: "ax-3"
}
]

But still can't do what i wanna do

uhbc left a reply on Set Variable For JSON.

I am pretty sure that data is not empty

uhbc started a new conversation Set Variable For JSON.

var variable = 'somevalue';

$.get(url, function(e){
console.log( e[0].variable );
});

How can i do something like this, i've tried almost everything but couldn't make it work.

-- The reason i wanna do that is, in the json output there are values like; a1, a2, a3 and i wanna get a1 when its 10pm and get a2 when its 5am ect.

I get an error like : " Cannot read property 'variable' of undefined "

Thanks.

07 Apr
1 year ago

uhbc left a reply on Ajax Get Method

Actually, the main purpose was about the 'Get Method', I have no idea how to use that.

uhbc left a reply on Ajax Get Method

shouldnt

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

do that?

uhbc left a reply on Ajax Get Method

@jlrdw done that but didn't work. In case, shouldn't it display the message for the other users, even it doesn't happen for me? But that's not displaying for other users too.

uhbc left a reply on Ajax Get Method

After submitting getting this in Response:

{"chat":"test123321123321","userid":131,"username":"asdasd","updated_at":"2018-04-08 02:04:28","created_at":"2018-04-08 02:04:28","id":664}

but still can't display it on the chat page.

uhbc left a reply on Ajax Get Method

Still couldnt

06 Apr
1 year ago

uhbc left a reply on Ajax Get Method

@Cronix then i replied with: If i do this, the page will be reloaded and its not really cool for the chat. Also, it doesnt data to db.

and then you: I don't think you copied everything correctly. The form shouldn't submit except by ajax. the e.preventDefault() makes it not submit the real form. You also had numerous items with the ID of "chat". ID's need to be unique per page.

I thought we were going on the old one after you said it.

uhbc left a reply on Ajax Get Method

@jlrdw ofc that one will work but, its a chat, like do you reload the page in facebook when you are speaking with your friend?

uhbc left a reply on Ajax Get Method

Actually same as i sent yesterday, i told you that i changed 'chat' into 'cett' and added console.log(response); after you told me to.

uhbc left a reply on Ajax Get Method

Sent the wrong one sorry, changed it.

uhbc left a reply on Ajax Get Method

<script>
$(document).ready(function(){


$('#send').click(function () {

  var cett = $('#cett').val();
  var username = $('#username').val();
  var userid = $('#userid').val();
  var token = $("#token").attr('content');


$.ajax({
  type:"POST",
  url:"{{url('chat')}}",
  data:"cett=" + cett + "&_token" + token,
  beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
  success: function (response) {
    console.log(response);
    $('#chat > .list-group').append(response);
}

});
});
});

</script>

uhbc left a reply on Ajax Get Method

@tykus, the view is at where you just said. I wrote that code and got this:

{"notifyType":"consoleItemLog","message":{"message":"","styles":"","hasFormatString":true,"fileUrl":"http:/site.com/home","lineNumber":150,"columnNumber":5}}

uhbc left a reply on Ajax Get Method

i got this:

{"notifyType":"consoleItemLog","message":{"message":"","styles":"","hasFormatString":true,"fileUrl":"http://35.196.31.255/home","lineNumber":151,"columnNumber":5}}

uhbc left a reply on Ajax Get Method

@tykus i changed codes into this and typed something:

    public function chat(Request $request) {
        // validate will throw a ValidationException if it fails, so no checks required
        $this->validate($request, [
            'cett'=> 'required|max:120|min:6',
        ]);

        // Since you have an Eloquent model, I am using that rather than Query Builder
        $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 dd($chat);
    }

I saw this in the chat after i sent it.: http://prntscr.com/j1v7n9

and the chat.message :

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

uhbc left a reply on Ajax Get Method

But still, i have to f5 to see what is written

uhbc left a reply on Ajax Get Method

Sorry, i got this one:

{"chat":"asdfsadfsadf","userid":128,"username":"Admin","updated_at":"2018-04-06 04:20:57","created_at":"2018-04-06 04:20:57","id":537}

uhbc left a reply on Ajax Get Method

{"html":""}

uhbc left a reply on Ajax Get Method

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

05 Apr
1 year ago

uhbc left a reply on Ajax Get Method

chats.message :

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

uhbc left a reply on Ajax Get Method

{"html":""}

uhbc left a reply on Ajax Get Method

response is {"test":"value"}

uhbc left a reply on Ajax Get Method

error log isnt changed.

uhbc left a reply on Ajax Get Method

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

uhbc left a reply on Ajax Get Method

Done but now i see a blank page.

uhbc left a reply on Ajax Get Method

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

uhbc left a reply on Ajax Get Method

How can i do that? Changed ajax codes into:

$.ajax({
  type:"POST",
  url:"{{url('chat')}}",
  data:"cett=" + cett + "&_token" + token,
  beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
  success: function (response) {
        $('#chat > .list-group').append(response); // response will be a HTML string
        console.log(response);
    }

});

And in console, there is nothing

uhbc left a reply on Ajax Get Method

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: 

uhbc left a reply on Ajax Get Method

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 left a reply on Ajax Get Method

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

uhbc left a reply on Ajax Get Method

\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}
"} 

uhbc left a reply on Ajax Get Method

<?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)

uhbc left a reply on Ajax Get Method

  <?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
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }


    public function chat(Request $request) {
        // validate will throw a ValidationException if it fails, so no checks required
        $this->validate($request, [
            'cett'=> 'required|max:120|min:6',
        ]);

        // Since you have an Eloquent model, I am using that rather than Query Builder
        $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?
        ]);

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



}

uhbc left a reply on Ajax Get Method

Logs:

[2018-04-06 01:30:30] local.ERROR: Namespace declaration statement has to be the very first statement or after any declare call in the script {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 64): Namespace declaration statement has to be the very first statement or after any declare call in the script at /var/www/0/public_html/app/Http/Controllers/ChatController.php:3)
[stacktrace]
#0 {main}
"} 


uhbc left a reply on Ajax Get Method

In the codes Tykus sent has:

      $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?
        ]);

Dont i also have to send the user's name, to see who sent the messages and show it on the screen?

uhbc left a reply on Ajax Get Method

I changed the input id 'chat' into 'cett' and in from chatcontroller as well. Here is the data: http://prntscr.com/j1infc

but i still get the error '500 Internal Server Error'.

uhbc left a reply on Ajax Get Method

If i do this, the page will be reloaded and its not really cool for the chat. Also, it doesnt data to db.

uhbc left a reply on Ajax Get Method

<input type="text" id="chat" value="" placeholder="Type your message here.." maxlength="120" class="form-control" autocomplete="off"><br />
                      <input type="hidden" id="userid"  value="{{Auth::user()->id}}">
                      <input type="hidden" id="username" value="{{Auth::user()->name}}">
                      <input type="hidden" id="token" value="{{ csrf_token() }}">
                      <input type="submit" class="btn-info btn-muted" value="Send!" id="send">

scripts:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<link rel="stylesheet" href="{{asset('css/anim.css')}}">



<script>
$(document).ready(function(){
$('#send').click(function () {

  var chat = $('#chat').val();
  var username = $('#username').val();
  var userid = $('#userid').val();
  var token = $('#token').val();


$.ajax({
  type:"POST",
  url:"{{url('chat')}}",
  data:"chat=" + chat + "&userid=" + userid + "&username=" + username + "&_token=" + token,
  beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
  success: function (response) {
        $('#chat > .list-group').append(response); // response will be a HTML string
    }

});
});
});

</script>

uhbc left a reply on Ajax Get Method

Dont know why but somehow, getting this error: http://prntscr.com/j1icjt

uhbc left a reply on Ajax Get Method

@Cronix when i hit submit and check the db, the 'This is a new data' text is in it. And when i wanna see the message in this here: http://prntscr.com/j1hses, i have to reload the page.

uhbc left a reply on Ajax Get Method

I was using the exact code he wrote up there. After it didn't work, went back to the old one.

uhbc left a reply on Ajax Get Method

Yes, when i add a new message, i have to F5 the page to see it. Not automatically appearing.

uhbc left a reply on Ajax Get Method

Isnt that possible to get data without refreshing page? automatically? with a little effect

uhbc left a reply on Ajax Get Method

Thanks but, now i have to f5 the page again to see what is written.

uhbc left a reply on Ajax Get Method

i got this error :

Non-static method App\ChatModel::recent() should not be called statically