khaledSMQ

khaledSMQ

Dubai

Member Since 3 Years Ago

Experience Points 26,440
Experience
Level
Lessons Completed 321
Lessons
Completed
Best Reply Awards 9
Best Answer
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.

30 Jun
1 year ago

khaledSMQ left a reply on Select2 Does Not Put All ID In The Query

@Xanger i think this should be like


$articoli->id_gioco =  implode(',',  $request->get('id_gioco'));
$articoli->id_console = implode(',',  $request->get('id_console'));


31 May
1 year ago

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

@Heyaj05 Thanks for asking,

Since you are working in back-end to back-end calls there will be no problems or any security problems just make sure if you are in production exceptions are not exposed to public in case there is any error UnhandledException thrown

06 Feb
1 year ago

khaledSMQ left a reply on Serialize Callable Function

i think you need to call closure after that cach

01 Feb
1 year ago

khaledSMQ left a reply on Route Group With Middleware And Parameters

i can see this in my case

Route {#166 ▼
  +uri: "user/jobcards/acl"
  +methods: array:2 [▼
    0 => "GET"
    1 => "HEAD"
  ]
  +action: array:5 [▼
    "middleware" => array:2 [▼
      0 => "web"
      1 => "\Eventoh\Http\Middleware\AclMiddleware:$role:data:help"// here what we want
    ]

khaledSMQ left a reply on Route Group With Middleware And Parameters

sorry for that i just forget computedMiddleware it's not available in L5.2

can you check dd($request->route())

khaledSMQ left a reply on Route Group With Middleware And Parameters

you can use $request->route()->computedMiddleware to fetch the middleware's and parse the data or prams you want

khaledSMQ left a reply on Route Group With Middleware And Parameters

Yes but not in group route method , sorry for that i missed it in first reply,

khaledSMQ left a reply on Route Group With Middleware And Parameters

try this might help you



Route::group(["prefix" => "/user/jobcards", "middleware" => ['\App\Http\Middleware\AclMiddleware:role']], function () {

    Route::get('/acl', function () {

        return response('done');
    });

});


class AclMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next )
    {
         dd($request->route()->computedMiddleware);
        return $next($request);
    }
}

khaledSMQ left a reply on Check If Text Is Encrypted Before Running Encrypt::decrypt($text)

okay, first of all by default Laravel uses AES-256-CBC and to determine if the data encrypted or not. It's depend on the string you are planing to encrypt, lets say if the string random ( no spaces, no english words ) means it's not possible to know, other wise you might think to use like space separator or try to find some words or use some helper functions like this

$plural = str_plural('child');
// from https://laravel.com/docs/5.4/helpers#paths

khaledSMQ left a reply on Show Response And Query Time

try this

 DB::listen(function ($query) {
            // $query->sql
            // $query->bindings
            // $query->time
        });

khaledSMQ left a reply on Internal Server Error When Posting Ajax Call.

can you dump your request

Route::POST('/changeDevNew', function(){
dd(Request()->all());
});

khaledSMQ left a reply on Old Values Not Displaying

can you do this please


<?php
// put this class in your  App\Http\Requests folder and make sure the namespace match your namespace
namespace App\Http\Requests;

use App\User;
use Illuminate\Foundation\Http\FormRequest;

class UserCreateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
           'username' => 'required|min:2',
            'email' => 'required|email',
            'password' => 'required',
        ];
    }
}


public function store(\App\Http\Requests\UserCreateRequest $request)
    {
         
        # Create
        $user = $this->create($request->all()))
        # Authenticate
        //auth()->login($user);

        # redirect
        return redirect()->home();
    }


protected function create(array $data)
    {
        return User::create([
            'name' => $data['username'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']), // always make sure not plain password in your database
        ]);
    }


khaledSMQ left a reply on Internal Server Error When Posting Ajax Call.

have you setup your CSRF token

<meta name="csrf-token" content="{{ csrf_token() }}">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
//or 

$.ajax({
 method: 'POST', 
 headers: {
        'X-CSRF-TOKEN': {{ csrf_token() }}
    }
.......

khaledSMQ left a reply on Laravel Should Fix Ability Add Related Tables Gets Created.

have you setup you csrf

<meta name="csrf-token" content="{{ csrf_token() }}">

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

khaledSMQ left a reply on Dynamic Survey App

or if the options is dynamic you need to create separate tables

like this

question table
Questions:
- id;
- survey_id;
- label;
- input_type;
- order;

options table
- question_id
- option (name or type or what ever)
- next_qustion_id

khaledSMQ left a reply on Dynamic Survey App

what if you link it in the same table like this

Questions: |-> -id; | - survey_id; |-> - question_id; - label; - input_type; - options; - order;

khaledSMQ left a reply on Uploading A File To A Laravel POST Route Through My C# Desktop Application And I'm Getting CSRF Mismatch Errors

I think you should not use web route for post form your C# application, instead you have to use API routes since it will not require CSRF but you need to got into authentication before posting depend on your requirements

https://laravel.com/docs/5.4/passport https://laravel.com/docs/5.4/passport#protecting-routes

khaledSMQ left a reply on Old Values Not Displaying

check the updated

khaledSMQ left a reply on Old Values Not Displaying

here is full code

   public function store(Request $request)
    {
         $v = Validator::make($request, [
             'username' => 'required|min:2',
            'email' => 'required|email',
            'password' => 'required',
        ]);

      if ($v->fails()) {
            return redirect('/registation form')
                        ->withErrors($v)
                        ->withInput();
        }

        # Create
        $user = User::create(request(['username', 'email', 'password']));

        # Authenticate
        //auth()->login($user);

        # redirect
        return redirect()->home();
    }


khaledSMQ left a reply on Old Values Not Displaying

yes you need to replace data with your request like this

$data = $request->only('username', ..... what ever data you want)

khaledSMQ left a reply on Old Values Not Displaying

why not using

php artisan make:auth

you will find great controllers out of the box for registration and login and forget password https://laravel.com/docs/5.4/authentication

khaledSMQ left a reply on Old Values Not Displaying

try

    $v = Validator::make($data, [
             'username' => 'required|min:2',
            'email' => 'required|email',
            'password' => 'required',
        ]);

    if ($v->fails()) {
            return redirect('your route here')
                        ->withErrors($validator)
                        ->withInput();
        }


``

khaledSMQ left a reply on Old Values Not Displaying

have you tried to use Request validation class, and try to change it to ``` {!! old('email') !!}

khaledSMQ started a new conversation How To Cache Model In Redis

Hi every one, I just recently started to work on caching and learn more about it, I would like to know if someone have experience for caching models and database queries especially update the cache after the data have been edited, Example , User model update the remember token changed every time you login, for this case i have to update my cached data, if you was in this kind if situation what is the best practice to follow and how to deal with cache data and update the memory for any changes.

27 Jan
1 year ago

khaledSMQ left a reply on Laravel Post Error

have you checked form method

<form method="POST">
17 Dec
1 year ago

khaledSMQ left a reply on Laravel Echo Not Getting Broadcast Event

Hi @laraadmin ,

it's a good idea to use laravel-echo-server if you care about authenticated private channels. if you are using Homestead for your development env, make sure to check the following steps

1- make sure supervisor is running in the background to keep tracking the queues. https://laravel.com/docs/5.3/queues#supervisor-configuration

2- in your handler Exception you need to add a piece of code for the broadcasting auth throwen exception.

if ($exception instanceof HttpException) {
    if ($exception->getCode() == 403) {

        return response([
                            'success' => false,
                            'code'    => $exception->getCode(),
                            'message' => $exception->getMessage()
                        ], 403);

    }

}

3- make sure you are not dumping any data in Handler.php ( laravel-echo-server will crash). 4- in your config/app.php you need to uncomment

 App\Providers\BroadcastServiceProvider

5- also don't forget in your .env what is the broadcast driver ( Redis ) 6- make sure to pass the arguments in your fired event

(
    broadcast (new App\Events\UserSignedUp($user->id)); // 
}

7- subscribe to "test-channel? then listen to ("UserSignedUp")

03 Dec
2 years ago

khaledSMQ left a reply on How To Count User Logins?

in laravel 5.3 you can override authenticated method in LoginController

 /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  mixed                    $user
     *
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {

         $user->loginCount++;
         $user->save();

    }

// this method will trigged once the user is authenticated
``
29 Nov
2 years ago

khaledSMQ left a reply on Trying To Get Property Of Non-object (View:

@Jayanthkumar if you are sure there is data in customer table just verify your arg ID you are passing to where

28 Nov
2 years ago

khaledSMQ left a reply on Require Email If User Not Logged In But Not Require It If User Logged In

simply you can do somthing like this

  $roles = [
        'name'          => 'required',
        'location'      => 'required',
        'contact_email' => 'required',
        'categories'    => 'required',
        'description'   => 'required'
    ];

    if (!Auth::check()) {
        $roles += [ 'email' => 'required|email|max:32|unique:users' ];
    }
 $this->validate($request, $roles);

khaledSMQ left a reply on Missing Argument 3 For App\Http\Controllers\ProjectCollaboratorsController::update()

i think your route is wrong


public function update(Request $request, $projectId, $collaboratorId)
....


Route::put('projects/{projectId}/{collaboratorId}/permission',['uses'=>'[email protected]',]);

khaledSMQ left a reply on Laravel Session Check

$value = $request->session()->pull('cart', 'default');

https://laravel.com/docs/5.3/session

khaledSMQ left a reply on Beanstalkd Job Handle Method Not Getting Executed

did you run this command

php artisan queue:work --queue=high,default


``
also you can check this 

https://laravel.com/docs/5.3/queues#supervisor-configuration

khaledSMQ left a reply on Trying To Get Property Of Non-object (View:

@JAYANTHKUMAR

simply the $row is null that's why you can do something like this

{{ old('email', @$row->email) }}
// by adding '@'  you will ignore email if it's null
``
23 Nov
2 years ago

khaledSMQ left a reply on Homestead Box 0.6.0 Release (Including VMWare Provider)

@SVPERNOVA09 i tried to update my homestead

vagrant box update "laravel/homestead"

getting this error

 ✝  ~  vagrant box update "laravel/homestead"
The machine with the name 'laravel/homestead' was not found configured for
this Vagrant environment.
 ✘ ✝  ~ 

can you please share how to update from 0.5.0 to 0.6.0

18 Nov
2 years ago

khaledSMQ left a reply on Ide-helper Doesn't Work, PHPStorm

@ALEXP11223 did you register service provider?

// in your App/Providers/AppServiceProvider.php/
public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
    }
 }

khaledSMQ left a reply on Reboot Ubuntu Server With PHP

Try this

//http://www.linuxquestions.org/questions/linux-newbie-8/shutdown-and-reboot-linux-system-via-php-script-713379/#post3486126


<?php
$command = "cat $pass | su -c 'shutdown -r now'";
$output = array();
try{
echo shell_exec($command);
exec($command, $output);
system($command, $output);
}Catch(Exception e){
print "Unable to shutdown system...\n";
}

foreach ($output as $line) {
print "$line<br>";
} 
?>

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

here is my full code and it's working i have tested

//laravel-worker.conf

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/vagrant/Code/Laravel/artisan queue:work redis --tries=3
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/home/vagrant/Code/Laravel/storage/logs/worker.log

// from https://laravel.com/docs/5.3/queues#supervisor-configuration



// server.js
require('dotenv').config();

const server = require('http').Server();

const io = require('socket.io')(server);

const Redis = require('ioredis');

const redis = new Redis();

redis.subscribe('all-channel');

console.log(process.env.SOCKET_PORT);

redis.on('message', function (channel, message) {
    const event = JSON.parse(message);
    io.emit(event.event, channel, event.data);
});

server.listen({
    port: process.env.SOCKET_PORT
});



// bootstrap.js
import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://homestead.app:6001'
});


// home.blade.php
 
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="{{ elixir('js/app.js') }}"></script>

<script>

    document.onreadystatechange = () => {
        if (document.readyState === 'complete') {
            console.log("doc is ready");
            Echo.channel('all-channel').listen('ServerCreated', function(e) {
                console.log(e);
            });
        }
    };

</script>



/// route/web.php


Route::get('publish', function () {
    $data = [
        'type'    => 'erhelloror',
        'title'   => 'new article has been published',
        'message' => 'check it out',
        'url'     => 'url',
    ];
    event(new \App\Events\ServerCreated($data));
    return 'done';
});



/// App\Events\ServerCreated
// event

class ServerCreated implements ShouldBroadcast
{

    use InteractsWithSockets, SerializesModels;

    public $data;


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


    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('all-channel');
    }

}


17 Nov
2 years ago

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

@geraldarcega can you provide more information

16 Nov
2 years ago

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

Hi @andfelzapata i think the missing part in your node server

// need to add 'channel' like bellow 
io.emit(emmitChannel, channel, notificacion.data);

15 Nov
2 years ago

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

also in the frame you can see the entire event namespace or just a number ?

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

What about

echo.channel('channel-notificaciones')
    .listen('BecaCargada', function(e) {
        console.log(e);
});

khaledSMQ left a reply on Laravel Echo Listening Is Not Receiving Data

Your welcome , sorry for late update. i think the problem is you have to listen for the jobs by running

php artisan queue:listen