Zaheer

Zaheer

Member Since 8 Months Ago

Experience Points
880
Total
Experience

4,120 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
880 XP
Oct
21
3 months ago
Activity icon

Started a new Conversation Error On Authenticated User Login

I am trying to define a Global Session Variable in Login Controller of Laravel 6.

protected function authenticated(Request $request, $user)
{
    $branch_id = auth()->user()->branch_id;
    session()->put('lbranch', $branch_id);
    if ($branch_id==0){
        $branchid = Branch::first('id');
        session()->put('lbranch', $branchid->id);
    }
}

But I am getting the following error :

Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request, instance of Illuminate\Http\Request given, called in E:\ZAH\Laravel\myaccounts\vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php on line 111

When I change :

use App\Http\Controllers\Auth\Request;

with

use Illuminate\Http\Request;

everything works fine. My question is what is the proper way of using authenticated function with Auth request.

Aug
10
5 months ago
Activity icon

Replied to Raw Query Generating General Error 2014

Thanks, I have already gone through this post. My solution was to collect data into arrays and then process to get desired result.

Activity icon

Started a new Conversation Raw Query Generating General Error 2014

One of my queries is generating following error : General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll().

Here is the query :

$query2 = DB::select(DB::raw("
     SELECT date,token,(select date from token b where gate='IN' and type='BIKE' and date(date) between :fd and :td and b.token=a.token) as intime,
     (select date from token c where gate='OUT' and type='BIKE' and date(date) between :fd1 and :td1 and c.token=a.token) as outtime,
     (select amount from token d where gate='OUT' and type='BIKE' and date(date) between :fd2 and :td2 and d.token=a.token) as amount
     FROM token a where type='BIKE' and date(date) between :fd3 and :td3 group by token"), 
     array('fd'=>$fd,'td'=>$td,'fd1'=>$fd,'td1'=>$td,'fd2'=>$fd,'td2'=>$td,'fd3'=>$fd,'td3'=>$td) );

I tried converting it to PDO but the error is still there. PDO query :

$q2 = "SELECT date,token,(select date from token b where gate='IN' and type='BIKE' and date(date) between '$fd' and '$td' and b.token=a.token) as intime,
      (select date from token c where gate='OUT' and type='BIKE' and date(date) between '$fd' and '$td' and c.token=a.token) as outtime,
      (select amount from token d where gate='OUT' and type='BIKE' and date(date) between '$fd' and '$td' and d.token=a.token) as amount FROM token a where type='BIKE' and date(date) between '$fd' and '$td' group by token";

$db2 = DB::connection('mysql');
$pdo2 = $db2->getPdo();
$pdo2->setAttribute( \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$stmt2 = $pdo2->query( $q2 );
$query2 = $stmt2->fetchAll();

Can someone suggest What is wrong with the query. Or can help convert it to Eloquent without using raw.

Jul
19
6 months ago
Activity icon

Replied to Left Join Within A Left Join

Found the solution. Correct query is :

$query = DB::table('autostk')
    ->where('autostk.branchid', $branch_id)
    ->where('autostk.itemcode',$request->itemcode)
    ->whereDate('autostk.date','<=',$request->tdate)
    ->leftjoin('journal AS j', function($join) use ($branch_id) {
        $join->on('autostk.refno', '=', 'j.vno')
        ->on('autostk.vtype', '=', 'j.vtype')
            ->where('j.code', '>=', 100)
            ->where('j.branchid', $branch_id)
            ->leftjoin('accounts', 'j.code', '=', 'accounts.code')
            ->where('accounts.branchid', $branch_id);
    })
    ->select('j.code','accounts.title','autostk.*')
    ->orderBY('autostk.date')->get()
    ->map(function ($item, $key) {
        return (array) $item;
    })
    ->all();
Activity icon

Started a new Conversation Left Join Within A Left Join

Can someone help fix this query. I am getting "null" result for "j.code" and "accounts.title" which should have a value. Is this the proper way of using left join within a left join. Here is my query :

$query = DB::table('autostk')
    ->where('autostk.branchid', $branch_id)
    ->where('autostk.itemcode',$request->itemcode)
    ->whereDate('autostk.date','<=',$request->tdate)
    ->leftjoin('journal AS j', function($join) use ($branch_id) {
        $join->on('autostk.refno', '=', 'j.vno')
            ->where('j.code', '>=', 100)
            ->where('j.branchid', $branch_id)
            ->where('j.vtype', '=', 'autostk.vtype')
            ->leftjoin('accounts', 'j.code', '=', 'accounts.code')
            ->where('accounts.branchid', $branch_id);
    })
    ->select('j.code','accounts.title','autostk.*')
    ->orderBY('date')->get()
    ->map(function ($item, $key) {
        return (array) $item;
    })
    ->all();

The raw query being generated is :

select `j`.`code`, `accounts`.`title`, `autostk`.* from `autostk`
left join (`journal` as `j` left join `accounts` on `j`.`code`=`accounts`.`code`)
on `autostk`.`refno` = `j`.`vno` and `j`.`code` >= ? and `j`.`branchid` = ?
and `j`.`vtype` = ? and `accounts`.`branchid` = ? where `autostk`.`branchid` = ?
and `autostk`.`itemcode` = ? and date(`autostk`.`date`) <= ? order by
`autostk`.`date` asc

UPDATE : While checking the QueryLog i noticed that the binding for 'j'.'vtype' is "autostk.vtype" Applying the query in workbench with 'autostk.vtype' returned null results. But when I changed it to 'autostk'.'vtype' the results showed up correctly. How to make this change in the Eloquent ?