mercredi 23 septembre 2015

How to safely update Laravel queues without errors?

I have a system with multiple web servers behind a load balancer. I also have one or more servers for running queued jobs (each server can also have more than one queue listener). The web servers push jobs on to redis (separate server) and the workers pull the jobs.

I'm trying to find the best way to update the code (git pull) in each of these locations without the workers having failed jobs due to code changes. An example would be removing a dependency. Queued jobs would still rely on the "old" code after running git pull. Thus, the job would error out since the dependency was removed.

Does anyone have insight on updating the queue workers without causing jobs to fail?



via Chebli Mohamed

Extending Authentication in Laravel 5.1

I have an application, similar to what hosting resellers get exept something different... this application is used on domainA.com and domainB.com. Both domains point at a single server, so both site run off single app exactly same files and single database.

When user accesses domainA.com we would see specific preferences for domainA i.e. logo and colour scheme. Same applies for domainB.com.

While both domains use single database, I want userA to be able to register on domainA and domainB with same email. When user is to try to login we would use something similar to: (taken from http://ift.tt/1Fu3ym1)

Auth::attempt(['email' => $email, 'password' => $password, 'site' => 'domainA.com'])

This is functionality that I require is needed in order to keep data separate so that if you login as an adminA that belongs to domainA.com you would see what userA did on domainA.com and adminA wouldn NOT see what userA did on domainB.com. Same applies to adminB that belongs to domainB.com, adminB wouldn't be able to see what userA did on domainA.com.

I would like to know on how overall Authentication supplied with Laravel 5 be affected if I was to update default AuthController@create method with something similar to:

    protected function create(array $data)
    {        
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'site' => 'domainB.com'
        ]);
    }

I assume that password reminder can be easily updated, but because Laravel's authentication includes quite alot of built in functionality this might pose an issue unless after authentication user's identifier is used to identify user and to perform core functions



via Chebli Mohamed

Integrating HTML2PDF in laravel 5.1

I am trying to integrate html2pdf library in laravel 5.1. But it is showing error like as follows Class 'App\Http\Controllers\HTML2PDF' not found and my controller code is as follows

require_once(dirname(__FILE__).'/libs/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0));
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($html22);

my folder path is app/Http/Controllers/libs/html2pdf/html2pdf.class.php

i had given the correct path but still it is showing error like HTML2PDF not found. Please anyone let me know how to integrate html2pdf ? or should i do any changes in compose.json file ?

and even i included the line App\Http\Controllers\HTML2PDF at the top of the Controller page but no use.

please help me out .

Thanks



via Chebli Mohamed

laravel 5.1 custom validation message same field name

I have in my application fields with the same name accross my models. For example I have a "firstname" field in both User Model and Teacher Model. I am using validation and specified custom validation messages in Language files (by adding language folders and validation.php files inside resources/lang). Is there a way to return different messages for same field name? For example i would like to do something like the following

'custom' => [ 
                'user.firstname' => [
                       'required' => 'message',            
                 ],
                 'teacher.firstname' => [
                       'required' => 'different message',            
                 ],
            ],



via Chebli Mohamed

Convert Mysql Query to Laravel Eloquent

I am using Laravel 5.1 in my application.

My MySQL Query is

SELECT * FROM (SELECT uu.*,t.left_id AS meb_id,(CAST(t.pair AS UNSIGNED) - IFNULL(p.pair,0)) AS pair FROM (SELECT left_id,
(CASE 
WHEN ((SELECT COUNT(meb_id) FROM user_count WHERE left_id=u.left_id AND active = 1 AND join_date <= '1442255400000') >= (SELECT COUNT(meb_id) FROM user_count WHERE right_id=u.left_id AND active = 1 AND join_date <= '1442255400000')*2) 
THEN (SELECT COUNT(meb_id) FROM user_count WHERE right_id=u.left_id AND active = 1 AND join_date <= '1442255400000')
WHEN ((SELECT COUNT(meb_id) FROM user_count WHERE left_id=u.left_id AND active = 1 AND join_date <= '1442255400000') < (SELECT COUNT(meb_id) FROM user_count WHERE right_id=u.left_id AND active = 1 AND join_date <= '1442255400000')*2) 
THEN ((SELECT COUNT(meb_id) FROM user_count WHERE right_id=u.left_id AND active = 1 AND join_date <= '1442255400000') /2)
WHEN ((SELECT COUNT(meb_id) FROM user_count WHERE right_id=u.left_id AND active = 1 AND join_date <= '1442255400000') >= (SELECT COUNT(meb_id) FROM user_count WHERE left_id=u.left_id AND active = 1 AND join_date <= '1442255400000')*2)
THEN (SELECT COUNT(meb_id) FROM user_count WHERE left_id=u.left_id AND active = 1 AND join_date <= '1442255400000')
WHEN ((SELECT COUNT(meb_id) FROM user_count WHERE right_id=u.left_id AND active = 1 AND join_date <= '1442255400000') < (SELECT COUNT(meb_id) FROM user_count WHERE left_id=u.left_id AND active = 1 AND join_date <= '1442255400000')*2)
THEN ((SELECT COUNT(meb_id) FROM user_count WHERE left_id=u.left_id AND active = 1 AND join_date <= '1442255400000') / 2) END
) AS pair
FROM user_count AS u WHERE  left_id <> 0 GROUP BY left_id) AS t
LEFT JOIN users AS uu ON uu.`id` = t.left_id
LEFT JOIN `total_payment` p ON t.left_id = p.`meb_id`
WHERE t.pair <> 0) AS f WHERE f.pair > 0  AND f.active = 1

How Can I convert it in Laravel Eloquent? I don't know how to use when case in laravel eloquent.

My Database schema is like this

user_count table enter image description here

user table enter image description here

total_payment table

enter image description here

Can anyone help me please?



via Chebli Mohamed

Send email using laravel

I have a contact form and I want to send email to the admin of the page when a visitor sends a message from the contact form.

  public function send(Request $request){
        Mail::send('email.message',[
            'request' => $request
        ], function($m) use ($request) {
            $m->from($request->email);
            $m->to('mail@domain.com', 'Name')->subject('Your Reminder!');
        });
   }

How can I configure it to send email without using gmail?



via Chebli Mohamed

mardi 22 septembre 2015

How to overwrite(Override class) public function asset($path, $secure = null) in Laravel

I wanna custom function

  public function asset($path, $secure = null)
  {
          if ($this->isValidUrl($path)) {
              return $path;
          }
          $root = $this->getRootUrl($this->getScheme($secure));
          return $this->removeIndex($root) . '/' . trim($path, '/');
  }

The code above from bootstrap/compile/cache.php. Please give me full example.



via Chebli Mohamed