mardi 13 septembre 2016

Updating MySQL database character set using Laravel

Is there a way to update a MySQL database character set using Laravel, perhaps the DB facade? I know I can just run the statement in something like MySQL Workbench, but I wanted to create a job that would run several updates to tables following the database update.

I wanted to run:

DB::statement("ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci");

But I'm getting an error:

SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll().

Is there a way I can accomplish what I'm trying to do or should I just run the statement separately from the job?



via Chebli Mohamed

How Can I change Default table for Auth::attempt() in laravel 5.0

I'm new to laravel and i am creating a authentication page i need to check the values for authentication in my own table but laravel is checking in users table

as my knowledge we can give in the user model

protected $table='my_own_table';

but i don't want to do this is there any way to change the default table of

Auth::attempt()

here is my code

function handleLogin(Request $request){
$data=$request->only('email','password');
if(\Auth::attempt($data))
{
   return "true";       
}
return "false";
}

in the above code when i excute it will check in the user table but i need to check in my_own_table is there any solution with out overriding the properties in the User model.



via Chebli Mohamed

How can I show captcha after 2 failed login attempts in Laravel?

How can I show captcha after 2 failed login attempts in Laravel ? I read the Throttle i protected maxLoginAttempts, how can I take it ? this is protected . please help . thanks all



via Chebli Mohamed

Laravel 5.1 belongs to many not working

I have following tables.

Users

id

name

Events

id

name

Cards

id

name

Transfers

id

event_id

card_id

I added the belongs to relationship in the Card.php as well as in Event.php

class Card extends Model
{
 public function user()
    {
        return $this->belongsTo(User::class);
    }

     public function events()
    {
        return $this->belongsToMany(Event::class,'transfers');
    }


}

class Event extends Model
{
        use SoftDeletes;

        protected $dates = ['deleted_at'];


    public function user()
    {
        return $this->belongsTo(User::class);
    }
    public function cards()
    {
        return $this->belongsToMany(Card::class,'transfers');
    }





}

I was trying to use the following statements in my controller both of them returned error

> echo count($user->events->cards->where([['id', '=',
> '57']])->find());die; //$cards is not defined.


> echo count($user->events->cards()->where([['id', '=',
> '57']])->find());die; // method cards() is not defined.I tried this after reading a tutorial

Any help on resolving this issue is appreciated.

Thanks in advance.



via Chebli Mohamed

lundi 12 septembre 2016

How to set no of Queue workers in laravel in windows and in shared server?

I am using Laravel 5.1, and I wanted to know if there is anyway with which we can increase the number of Queue workers in laravel... In its documentation, it's specified that we can do it by changing numprocs parameter with the help of Supervisor... But, how to do this on windows, as Supervisor is supported for only UNIX-based OS(es)... Also, Most probably, I will be deploying my application on Linux based shared server, so how to install supervisor there (because, server being shared, I don't think root access would be provided to me)??

Just for info, I am using database queue driver...

Thanks in Advance!



via Chebli Mohamed

Dom-pdf not rendering some characters

Im using vsmoraes/laravel-pdf for pdf generation. Its working fine for english characters but when its comes to other languages like chinese, greek its showing the ???? as below image

enter image description here

I have tried this one but went wrong. Anybody had this problem before?



via Chebli Mohamed

Laravel Queues for multi user environment

I am using Laravel 5.0, and I have a task that takes around 2 minutes to process, and this task particularly is generating a report...

Now, it is obvious that I can't make the user wait for 2 minutes on the same page where I took user's input, instead I should process this task in the background and notify the user later about task completion...

So, to achieve this, Laravel provides Queues that runs the tasks in background (If I didn't understand wrong), Now for multi-user environment, i.e. if more than one user demands report generation (say there are 4 users), so being the feature named Queues, does it mean that tasks will be performed one after the other (i.e. when 4 users demand for report generation one after other, then 4th user's report will only be generated when report of 3rd user is generated) ??

If Queues completes their tasks one after other, then is there anyway with which tasks are instantly processed in background, on request of user, and user can get notified later when its task is completed??



via Chebli Mohamed