vendredi 22 décembre 2017

Need help in optimising Laravel Mysql query

Can anyone help me out in explaining this below query in detail? This is part of my project which i got to debug. i need help to understand it and optimise this.

$query = seller::selectRaw("seller.name, seller.group_id,seller.group_id_string, seller.pay,( 
    SELECT SUM( IF( t.retail_cost >0
    AND t.submitted_group_plan >1, 1 , -1 ) ) AS trans_number
    FROM money AS t
    JOIN  `seller` AS d ON  `t`.`submitted_group_plan` =  `d`.`group_id` 
    WHERE 
    (
        (
        t.`claim_date_and_time` >=  '01-01-2015'
        AND t.`claim_date_and_time` <=  '01-01-2016'
        AND t.commissionable =  'Y'
        AND t.`submitted_group_plan` = d.group_id
        )
        OR 
        (
            (t.commissionable IS NULL)
            AND 
            (t.claim_type_code IS NULL)
            AND
            (t.claim_date_and_time IS NULL)
        )
    )
    AND d.id = seller.id)
    as trans_number");  

MYSQL VERSION OF ABOVE QUERY:

SELECT seller.name,
       seller.group_id,
       seller.group_id_string,
       seller.pay,

  (SELECT SUM(IF(t.retail_cost >0
                 AND t.submitted_group_plan >1, 1, -1)) AS trans_number
   FROM money AS t
   JOIN `seller` AS d ON `t`.`submitted_group_plan` = `d`.`group_id`
   WHERE ((t.`claim_date_and_time` >= '01-01-2015'
           AND t.`claim_date_and_time` <= '01-01-2016'
           AND t.commissionable = 'Y'
           AND t.`submitted_group_plan` = d.group_id)
          OR ((t.commissionable IS NULL)
              AND (t.claim_type_code IS NULL)
              AND (t.claim_date_and_time IS NULL)))
     AND d.id = seller.id) AS trans_number
FROM `seller`



via Chebli Mohamed

mercredi 20 décembre 2017

How to calculate between hours from current date to pickupdate in Laravel

How to calculate between hours from current date to pickupdate. I have pickup date and pickup Time from Input. below function returns wrong value.

$bookingtime=strtotime($request->input('pickupdate_submit')." ".$request->input('pickuptime_submit') );

        $curentdate=date('Y-m-d HH:i');
        $curenttime=strtotime($curentdate);

        $betweenhours = abs($bookingtime - $curenttime) / 3600;



via Chebli Mohamed

lundi 18 décembre 2017

Change Login Table in Laravel 5.5

I have two table one is "clUser" in which i am storing email id, another table name "clLogin" in which i am storing Password. How to change laravel default login with these two table.



via Chebli Mohamed

mardi 12 décembre 2017

Update form only if there is some change in the input fields

How to determine in update() method of a controller in a laravel project if there is any change in the input? I need to update form only if there is any change in the input fields.



via Chebli Mohamed

lundi 11 décembre 2017

Laravel 5.1 I cant update model $user

I have this function where I want to update user background image so I write:

public function updateBg(Request $request)
    {
        $user = Auth::user();
        $this->validate($request, [
            'background' => 'image|max:10000',
            // validate also other fields here
        ]);
        // checking file is valid.
        if (!$request->file('background')->isValid()) return redirect()->back()->withErrors(["background" => "File is corrupt"]);

        // file is valid
        $destinationPath = public_path().'/images/Custaccounts/'.$user->id; // upload path
        $extension = $request->file('background')->getClientOriginalExtension(); // getting image extension
        $ran = str_random(5);
        $photo  = $ran.'.'.$extension;

        $request->file('background')->move($destinationPath, $photo); // uploading file to given path

        $bg = $user->id.'/'.$photo;
dd($bg);
        $user->update(['background' => $bg]);

        return Redirect::back();

            }

this line wont work: $user->update(['background' => $bg]); dd($bg) give me right string and image is uploaded just I cant update my 'background; field ...

also when I write:

    $user->update(['background' => $bg, 'name'=>'John']);

name is updated but background not... at user model background field is fillable of cource



via Chebli Mohamed

dimanche 10 décembre 2017

How to access passed data inside a redirect route from blade template

I have a method that redirect to a route like this with a data passed inside it:

return redirect('vendors')->with('vendor',$allvendors);

and i want to access the data that i passed from a blade template that the redirect is pointing to, so i did something like this:

@foreach($vendor as $vendors)

but i am getting this error:

Undefined variable: vendor (View: /opt/lampp/htdocs/easyhire-web/resources/views/vendor/vendors.blade.php)

I rely don't know what i am doing wrong, but when i return a view with that same data, it will work but if i change it to redirect, it will give error. any help out there?



via Chebli Mohamed

jeudi 7 décembre 2017

Laravel 5: Store artisan console table output in a variable

In Laravel 5 console commands, you can output a table like so:

$this->table($headers, $tableData);

This is described here: http://ift.tt/2j4EAW2

However this outputs it straight to the console.

How can I store it in a variable without sending the data to the console.



via Chebli Mohamed