jorge_dev96

jorge_dev96

Member Since 5 Months Ago

Experience Points
540
Total
Experience

4,460 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
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
540 XP
May
23
2 months ago
Activity icon

Started a new Conversation ListenWhisper Doesn't Receive An Client Event (Larave-echo & Vue.jsl)

I'm working in a realtime chat website using Laravel, laravel-echo,laravel-echo-server, and redis. My chat is able to receive and send messages, but I want to add a message when a user start to typing ('User x is typing...'). But the client event is typing triggered

I have diferent vue.js components in this chat,

ChatApp.vue <- Main component

...
        mounted() {
            Echo.private(`message.${this.user.id}`)
            .listenForWhisper('.typing', (e) => { // This is listening for client event named typing
                console.log(e);
                setTimeout(function() {
                    console.log('works');
                }, 900);
            })
            Echo.private(`messages.${this.user.id}`) 
            .listen('.NewMessage', (e) => { //This is listening for a backend event named New Message
                this.handleIncoming(e.message);
                this.playSoundNotification();
            });
            axios.get('/user/contacts')
            .then((response) => {
                console.log(response.data);
                this.contacts = response.data;
            });
        },
....

MessageComposer.vue component

<template>
    <div class="composer">
        <span @typing="typing_handler" v-show="typing" class="help-block" style="font-style: italic;">
            Tú amigo esta escribiendo...
        </span>
        <textarea v-model="message" @keydown="isTyping" @keydown.enter="send" placeholder="Message..."></textarea>
    </div>
</template>

<script >
export default {
    data(){
        return {
            message: '',
            typing:false,
        };

    },
    methods: {
        send(e){
            e.preventDefault();
            if(this.message == ''){
                return;
            }

            this.$emit('send', this.message);
            this.message = '';
        },
        typing_handler(trigger){
            this.typing = trigger;
        },
        isTyping() {
            let  self_user_id = parseInt($('#self_user_id').val());
               var channel = Echo.private(`message.${self_user_id}`); //Client auth

                setTimeout(function() {
                    channel.whisper('typing', {
             
                        typing: true
                    });
                }, 300);

            },
    }
}
</script>

I don't get any error in my laravel-echo-server so I don't know what the problem is? What I'm doing wrong?

May
03
3 months ago
Apr
23
3 months ago
Activity icon

Started a new Conversation Response Does Not Support The Following Options: "no-cache".

I want to use the cache-controll headers in Laravel 5.8 I followed this tutorial

https://itnext.io/laravel-the-hidden-setcacheheaders-middleware-4cd594ba462f

So I create put a middleware in my / route

Route::get('/', function () {
    return view('welcome');
})->middleware('cache.headers:no-cache,private,max-age=300;etag');

But I get this error Response does not support the following options: "no-cache".

What should I do?

Apr
15
3 months ago
Activity icon

Started a new Conversation I Don't Receive A Broadcast Message In The Front End Laravel-echo-server

I'm currently working chat webpage with laravel-echo-server package in Laravel, I'm trying to show a message to send a message to one user and receive that message in realtime, but when I send a message it loads in my chat but the other user doesn't receive anything until I refresh the site. I think that laravel-echo-server isn't broadcasting correctly, but I don't know how to how to solve it. I checked if the event was correctly executed and it does but I dont' receive nothing. Can you help me? I'm using redis has a broadcaster and it seems to work correctly I added it to .env as a BROADCAST_DRIVER=redis and QUEUE_CONNECTION=redis

ChatApp.vue

     ......
mounted() {
    console.log(this.user);
    Echo.private(`messages.${this.user.id}`)
     .listen('NewMessage', (e) => {
          console.log(e);
          if (this.selectedContact && e.message.from == this.selectedContact.id){
                    this.saveNewMessage(e.message);
                    alert('fired');
                }
      });

channels.php authenticate messages between users


Broadcast::channel('messages.{id}', function ($user, $id) {
    //dd($user->id, $id);
    var_dump($user);
    return (int) $user->id === (int) $id;
});

NewMessage.php This is my event

class NewMessage implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Message $message)
    {
        $this->message = $message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('messages.'.$this->message->to);
    }
    public function broadcastWith()
    {
        return ["message" => $this->message];
    }
}

ContactsController.php I use send fuction when I user send a message to a other user and after I broadcast


Im getting this in my terminal when a user send a message to other user but the other user doesn't receive noting until I refresh


C:\laragon\www\newchat
λ laravel-echo-server start

L A R A V E L  E C H O  S E R V E R

version 1.6.1

⚠ Starting server in DEV mode...

✔  Running at localhost on port 6001
✔  Channels are ready.
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

[15:28:39] - Preparing authentication request to: http://newchat.test
[15:28:39] - Sending auth request to: http://newchat.test/broadcasting/auth

[15:28:40] - hq3MFtdUmFgfBB7WAAAA authenticated for: private-messages.2
[15:28:40] - hq3MFtdUmFgfBB7WAAAA joined channel: private-messages.2
[15:28:59] - Preparing authentication request to: http://newchat.test
[15:28:59] - Sending auth request to: http://newchat.test/broadcasting/auth

[15:29:00] - hf8Ginp5is-fyZLGAAAC authenticated for: private-messages.1
[15:29:00] - hf8Ginp5is-fyZLGAAAC joined channel: private-messages.1
Channel: chatapp_database_private-messages.7
Event: App\Events\NewMessage
...
class ContactsController extends Controller
{
    public function get()
    {
        $contacts = User::where('id', '!=' ,auth()->id())->get();
        return response()->json($contacts);
    }

    public function getMessagesFor($id)
    {
        $messages = Message::where('from', $id)->orWhere('to', $id)->get();
        return response()->json($messages);
    }
    public function send(Request $request)
    {
        $message = Message::create([
            'from' => auth()->id(),
            'to' => $request->contact_id,
            'text' => $request->text
        ]);
        broadcast(new NewMessage($message));
        return response()->json($message);
    }
}

...

Also Im using this command executed together with laravel-echo-server

 php artisan queue:listen --tries=1
Activity icon

Started a new Conversation Problem With Laravel-echo-server Aurhentication

hello friends im using laravel-echo-server as alternative of pusher.js in this tutorial https://youtu.be/7r4s3kS5ItM

But when I tried to send data to socket.io this happens

bbRyazR6mzPsjb5fAAAC could not be authenticated to private-messages1

I checked several similar questions in StackOverflow

https://stackoverflow.com/questions/47950431/laravel-echo-server-404-when-trying-to-authenticate but none of these questions helped me

What I'm doing wrong? HELP :c

routes/channels.php

Broadcast::channel('messages.{id}', function ($user, $id) {
    dd($user->id, $id);

    return (int) $user->id === (int) $id;
});

My event (with ShouldBroadcast )

class NewMessage implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    public $message;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Message $message)
    {
        $this->message = $message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('messages.'.$this->message->to);
    }
    public function broadcastWith()
    {
        return ["message" => $this->message];
    }
}

config/app.php

I've uncommented this line App\Providers\BroadcastServiceProvider::class,

My vue component

....

Echo.private(`messages${this.user.id}`)
            .listen('NewMessage', (e)=>{
                this.handleIncoming(e.message);
    });

My bootstrap.js

...
import Echo from "laravel-echo"
window.io = require('socket.io-client');

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001' // this is laravel-echo-server host
});

The log of my error

[16:50:41] - Sending auth request to: http://newchat.test/broadcasting/auth

⚠ [16:50:42] - bbRyazR6mzPsjb5fAAAC could not be authenticated to private-messages1
{
    "message": "",
    "exception": "Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException",
    "file": "C:\laragon\www\newchat\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\Broadcaster.php",
    "line": 81,
    "trace": [
        {
            "file": "C:\laragon\www\newchat\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\RedisBroadcaster.php",
            "line": 69,
            "function": "verifyUserCanAccessChannel",
            "class": "Illuminate\Broadcasting\Broadcasters\Broadcaster",
            "type": "->"
        },
        {
            "file": "C:\laragon\www\newchat\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastManager.php",
            "line": 320,
            "function": "auth",
            "class": "Illuminate\Broadcasting\Broadcasters\RedisBroadcaster",
            "type": "->"
        },
        {
            "file": "C:\laragon\www\newchat\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php",
            "line": 261,
            "function": "__call",
            "class": "Illuminate\Broadcasting\BroadcastManager",
            "type": "->"
        },
        {
            "file": "C:\laragon\www\newchat\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastController.php",
            "line": 23,
            "function": "__callStatic",
            "class": "Illuminate\Support\Facades\Facade",
            "type": "::"
        },
        {
            "function": "authenticate",
            "class": "Illuminate\Broadcasting\BroadcastController",
            "type": "->"
        },
.....
}
Client can not be authenticated, got HTTP status 403
Mar
20
4 months ago
Activity icon

Started a new Conversation WOW.js Hide My HTML Elements

Hello, i'm trying to use the frontend library WOW.js but it hide my HTML elements when I added a class.

I installed WOW.js with the following commands:

npm install wowjs --save

and I added this to bootstrap.js

const WOW = require('wowjs');
window.wow = new WOW.WOW({ live: false });
window.wow.init();
Mar
01
5 months ago
Activity icon

Replied to Save A File With The Real Extension Of A File Not Tmp Extension

Sorry for my questions the trouble is in this part

Wrong $copy["test_image"]->move(public_path('/storage/',$imageName));

Good

$copy["test_image"]->move(public_path('/storage/'),$imageName);

Activity icon

Replied to Save A File With The Real Extension Of A File Not Tmp Extension

Sorry I press best answer by error.

It Is dynamically loaded with a javascript file , this is the part of the input for images

<input id="profile_image_${number_of_questions}" type="file" class="" name="question_group[${number_of_questions}][test_image]">
Activity icon

Started a new Conversation Save A File With The Real Extension Of A File Not Tmp Extension

I'm trying to save an image from a multiple array object, the object is like this

array(4) {
  ["question"]=>
  string(13) "safasdhrewrtj"
  ["type"]=>
  string(16) "multiple_options"
  ["options"]=>
  array(2) {
    ["option_2"]=>
    string(10) "sfafasgved"
    ["option_1"]=>
    string(17) "eggrfwefszwgzegds"
  }
  ["test_image"]=>
  object(Illuminate\Http\UploadedFile)#268 (7) {
    ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
    bool(false)
    ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
    string(39) "fabio-spinelli-28P74KO_l3k-unsplash.jpg"
    ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
    string(10) "image/jpeg"
    ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
    int(0)
    ["hashName":protected]=>
    NULL
    ["pathName":"SplFileInfo":private]=>
    string(43) "C:\Users\neo\AppData\Local\Temp\php5D7E.tmp"
    ["fileName":"SplFileInfo":private]=>
    string(11) "php5D7E.tmp"
  }
}

As you can see it is an array of n elements with a test_image as an array with an object inside

I have this foreach loop to access trouh the object

foreach($request->all()["question_group"] as $copy){
        //$this->validate($request->all()['question_group'], [
        //    'test_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        //]);
        $imageName = uniqid().'.'.$copy["test_image"]->getClientOriginalExtension();
        $copy["test_image"]->move(public_path('/storage/',$imageName));

}

it saves the file but with a .tmp extension. And I dont know how to change it.

Feb
23
5 months ago
Activity icon

Replied to To Many Redirects Error After Adding A Custom Middleware

Should I change my middleware to this ?

$this->middleware('checktest')->except(['index'])
Activity icon

Started a new Conversation To Many Redirects Error After Adding A Custom Middleware

Hello, again, I added this middleware to check if the user answered a test

My middleware

public function handle($request, Closure $next)
 {
        if (Auth::user()->test == 0){ // 0 for not answered test, 1 for answered test
            return redirect()->route('home');
            //echo "Lol";
            //echo Auth::user()->test; 
        }
        return $next($request);
 }

but when I login or registered i received a To many Redirects error

I added two middlewares in this controller auth and my custom middleware checktest

<?php

...

class HomeController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('checktest');
    }


    public function index(Request $request)
    {

        $users = User::where('id', '!=', auth()->user()->id)->get();
        return view('home', ['users' => $users]);

    }
}

My kernel.php file

    protected $routeMiddleware = [
        'auth' => \ILink\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \ILink\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'checktest' => \ILink\Http\Middleware\CheckIfUserAnsweredTest::class,

    ];

What can I do ?

Feb
22
5 months ago
Activity icon

Replied to Add Attributes To My Auth()->user Session

I solved it I don't know how but I create separate migrations for my custom values and now it works witout this public function getUsernameAttribute() { return $this->username; }

Activity icon

Replied to Add Attributes To My Auth()->user Session

It works with other attributes like auth()->user()->email but not with my custom attributes :c

Activity icon

Replied to Add Attributes To My Auth()->user Session

I have this in my controller

public function index(Request $request)
    {
        echo "<pre>";
        dd(auth()->user()->username);
        echo "</pre>";
        die();
}
Activity icon

Replied to User Model Doesn't Recognize New Attributes

ILink is the name of my project instead of App, what is a trait :c

Activity icon

Started a new Conversation User Model Doesn't Recognize New Attributes

I created my users table with php artisan make:auth and I modified the original migration adding username attribute, but when I try to select a username it doesn't work

        $users = User::select('name','username')->where('username', 'LIKE', '%'.$request->input('username').'%')->get();

I get this

      {message: "Undefined property: ILink\User::$username", exception: "ErrorException",…}
protected $fillable = [
        'name','username', 'email', 'password','profile_image'
    ];

but username is actually in $fillable array

Activity icon

Replied to Add Attributes To My Auth()->user Session

User {#261 ▼
  #fillable: array:5 [▼
    0 => "name"
    1 => "username"
    2 => "email"
    3 => "password"
    4 => "profile_image"
  ]
  #hidden: array:2 [▼
    0 => "password"
    1 => "remember_token"
  ]
  #casts: array:1 [▶]
  #connection: "mysql"
  #table: "users"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:10 [▼
    "id" => 1
    "name" => "Marcia Bruen III"
    "username" => "rboehm"
    "email" => "[email protected]"
    "email_verified_at" => "2020-02-19 21:07:14"
    "password" => "yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi"
    "profile_image" => null
    "remember_token" => "VYnO7NoynsHlNnwoHgzHw0T0vCYHI4MU09K1QtGvw8sEKJo55cXlQ9j6kpLG"
    "created_at" => "2020-02-19 21:07:14"
    "updated_at" => "2020-02-19 21:07:14"
  ]
  #original: array:10 [▼
    "id" => 1
    "name" => "Marcia Bruen III"
    "username" => "rboehm"
    "email" => "[email protected]"
    "email_verified_at" => "2020-02-19 21:07:14"
    "password" => "yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi"
    "profile_image" => null
    "remember_token" => "VYnO7NoynsHlNnwoHgzHw0T0vCYHI4MU09K1QtGvw8sEKJo55cXlQ9j6kpLG"
    "created_at" => "2020-02-19 21:07:14"
    "updated_at" => "2020-02-19 21:07:14"
  ]
  #changes: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #visible: []
  #guarded: array:1 [▶]
  #rememberTokenName: "remember_token"
}
Feb
21
5 months ago
Activity icon

Started a new Conversation Add Attributes To My Auth()->user Session

Hi im trying to access to my attribute username auth->user->username but it says that username doesnt exist while username is actually in my model and in my database. I created a mutator in my model User, but idoesnt retrieve the username. It actually works with email, name, id atributters but not with username. What can I do :C

 <?php

 namespace ILink;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

    
class User extends Authenticatable
{
    use Notifiable;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name','username', 'email', 'password','profile_image'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

       public function getUsernameAttribute()
       {
            return $this->username;
        }

 }
```