jeudi 26 novembre 2015

get total number of queued jobs laravel -- RabbitMQ

new to Laravel, I'm using RabbitMQ with it, So, what I want is to get total number of queued jobs in some specific queue.

here are my connection details

RABBITMQ_HOST=Server
RABBITMQ_PORT=5672
RABBITMQ_VHOST=/
RABBITMQ_LOGIN=user
RABBITMQ_PASSWORD=password
RABBITMQ_QUEUE=testQueue
RABBITMQ_EXCHANGE_NAME=testExchnge

any clue, or pointing to some tutorial to get total queued jobs.

Thanks



via Chebli Mohamed

How to break a line in blade templete on laravel insted of

I can not break line in Blade templete on laravel framework . Please help me to print each element in one line . Code is given below

@for ($i = 0; $i < 10; $i++)
    The current value is {{$i}}

@endfor



via Chebli Mohamed

assertRedirectedToRoute not working in Laravel 5.1

Controller code:

return redirect()->route('admin.patient.edit', $patientId);

Test code:

$this->visit(route('admin.patient.edit', $this->patient->id))
     ->press('Update');

$this->assertRedirectedToRoute('admin.patient.edit', [$this->patient->id]);

The error I get is this:

Failed asserting that Illuminate\Http\Response Object (...) is an instance of class 
"Illuminate\Http\RedirectResponse".

I've printed out the response from the inside the test and inside the controller and it is in fact a RedirectReponse Object. Any ideas?



via Chebli Mohamed

Image mime type is different based on which PHP Server I use

I have this image file that when I test in my local environment then PHP determines it is of type

image/jpeg

However that same code and same image on my server gets detected as

application/octet-stream

What could be causing this behavior?

Image Size: 2.31 MB 
Name: ^EC91F66F648FD45E7BF3BE9D2169E239D41E49B794EA71E326^pimgpsh_fullsize_distr (1).jpg

Local Environment

PHP: 5.6.15

Live Environment

PHP: 5.6.9



via Chebli Mohamed

Connect to MySQL DataBase with Laravel 5.1 and Cloudways

I'm trying cloudways as server to deploy my Laravel application on it. Everythings seems to work, except that I can't connect to Database. When I try to authenticate, I get this error :

SQLSTATE[HY000] [2003] Can't connect to MySQL server on '***.***.**.***' (4)

There is my .env files :

DB_HOST=localhost
DB_DATABASE=ynjrzmznup
DB_USERNAME=ynjrzmznup
DB_PASSWORD=**********

I tried to reach it using terminal :

$ mysql -u ynjrzmznup -h localhost -p

And i got this:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2562
Server version: 5.5.46-0+deb7u1 (Debian)

Everything work on my local environment. I can reach every public files on the server, but when I try to authenticate, I can't because the server is unable to get data from MySQL.



via Chebli Mohamed

User object to every controller if authenticated

The 'problem' I'm facing now is that with every controller that is used when the user is authenticated I have to request $user = Auth::user();. An example:

public function store(Request $request)
{
    $user = Auth::user();

    $building = Building::findOrFail($request->building);
    $user->buildings()->save($building);

    return response(['status' => 'OK']);
}

As you can imagine I need to request the user object many more times, even in this one controller. How can I improve this? I have thought about declaring a user variable in the Controller parent class, or using Middleware. I read about dependency injection but I don't fully understand it and I can't figure out how to implement it well.



via Chebli Mohamed

Laravel - insert multiple models from appended inputs

I'm new to Laravel and I'm trying to insert n models from n appended html inputs Does Laravel's `Eloquent have a better way than this ?

public function store(Request $request, Domain $domain, Server $server)
{
    $new_domain = $domain->create($request->all());
    $server->fill($request->only(['srv_hostname','srv_ip','srv_port']));
    $servers = array();
    $total = count($server['attributes']['srv_hostname']);
    for ($i=0;$i<$total;$i++){
        $p = new Server;
        $p->domain()->associate($new_domain);
        $p->srv_hostname = $server['attributes']['srv_hostname'][$i];
        $p->srv_ip = $server['attributes']['srv_ip'][$i];
        $p->srv_port = $server['attributes']['srv_port'][$i];
        $p->save();
    }
    return redirect()->route('domains.index');
}



via Chebli Mohamed