mshakeel

mshakeel

Karachi

Member Since 3 Years Ago

Experience Points 1,360
Experience
Level
Lessons Completed 6
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

12 Jan
3 years ago

mshakeel started a new conversation Query Builder: Union Within Closure Giving Syntax Error - Extra Parenthesis

Following is query which uses union within closure:

protected function test()
{
    // Get All skill level metadata ids Query
    $skillMetaDataQuery = \DB::table('metadata_field_options')
        ->select('id')
        ->where('metadata_field_id', '=', function ($query) {
            $query->select('id')
                ->from('metadata_fields')
                ->where('field', '=', 'skill_level');
        });
    $filterCallback = function ($query) use ($skillMetaDataQuery) {
            $query->select('metadata_field_option_id')
                ->from('profile_extended')
                ->where('profile_id', 1)
                ->union($skillMetaDataQuery);
        };

    $users = User::where('users.id', '<>', 1)
        ->join('profiles as p', 'users.id', '=', 'p.user_id')
        ->join('profile_extended as pe', 'pe.profile_id', '=', 'p.id')
        ->whereIn('pe.metadata_field_option_id', $filterCallback)
        ->get();

    return $users;
}

It gives syntax error near join which is because of the parenthesis added with each union query, it is fixed when we made a slight change in framework file. Following is the change:

/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php change from

if ($query->unions) {
        $sql = '('.$sql.') '.$this->compileUnions($query);
    }

to

if ($query->unions) {
        $sql = $sql.' '.$this->compileUnions($query);
    }

There is already a bug reported where I have found this solution: https://github.com/laravel/framework/issues/5457

Question: Am I doing anything wrong here or should we create or reopen an issue on github.

04 Dec
3 years ago

mshakeel left a reply on Multi Line Environment Variable

@Snapey I have tried quoting the entire string, '\n' & '' at the end of each line

02 Dec
3 years ago

mshakeel started a new conversation Multi Line Environment Variable

We are using https://github.com/layerhq/layer-identity-token-php to generate identity token and have added private key in .env file like following:

LAYER_PRIVATE_KEY=-----BEGIN RSA PRIVATE KEY-----
keyxxxxxxxxxxxxxxxxxxxxxxxxx-----------
-----END RSA PRIVATE KEY-----

but it only returns first line (i.e. -----BEGIN RSA PRIVATE KEY-----) and therefore identity token can't be generated.

Please help how to store this key within .env file

Setting this key within code like following is working fine but we want to store it in .env

$privateKey                 = <<<EOF
-----BEGIN RSA PRIVATE KEY-----
keyxxxxxxxxxxxxxxxxxxxxxxxxx-----------
-----END RSA PRIVATE KEY-----
EOF;
$layerIdentityTokenProvider->setPrivateKey($privateKey);
27 Nov
3 years ago

mshakeel started a new conversation Dingo Api: Can't Add Transformers Within Response

Want to add a transformed object along with other response, I have used following code:

$accessToken = Authorizer::issueAccessToken();

    $user = User::where('email', $request->get('username'))->with('profile')->first();
    if ($user) {
        $accessToken['user'] = $this->response->item($user, new UserTransformer);
    }

    return $accessToken;

Expected Response:

{
    "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "token_type": "Bearer",
    "expires_in": 31536000,
    "data": {
      "id": 1,
      "email": "xxxxx",
      "profile": {
        "data": {
          "id": 1,
          "first_name": "Muhammad",
          "last_name": "Shakeel",
        }
      }
    }
}

but not getting transformed object, there must be some better way to add multiple transformed objects with response. Am I missing something?

PS: Returning only the transformed object as following works correctly and sends transformed object:

return $this->response->item($user, new UserTransformer);
12 Nov
3 years ago

mshakeel left a reply on OrderBy Resultset With Related Column

Thanks alot, yes it is working fine. I was missing the records after sorting.

mshakeel left a reply on OrderBy Resultset With Related Column

@pmall Thanks, It worked as expected. But I found the actual problem i.e. eager loading works with inner join but failed to load if we use leftJoin.

The following query will not eager load due to left Join

$users = User::with('profile')->select('users.*')
    ->join('profiles', 'users.id', '=', 'profiles.user_id')
    ->orderBy('profiles.first_name')
    ->get();

mshakeel left a reply on OrderBy Resultset With Related Column

@bobbybouwmann @pmall , Thanks for your answers.

Joining the tables as suggested works fine with the sort but it does not attach related column in my case. Since I am using Fractal transformer to ultimately send a response from my api (dingo api used).

$users = $user->otherUsers()->paginate($this->limit);
return $this->response->paginator($users, new UserTransformer);

/**
 * Scope a query to only include popular users.
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function scopeOtherUsers($query)
{
    return $query->where('users.id', '<>', $this->id)
        ->with('profile')
        ->leftJoin('profiles as p', 'p.user_id', '=', 'users.id')
        ->orderBy('p.first_name', 'asc');
}

mshakeel left a reply on Is There An Easy Way To Find Out Where Are My Queries Are Being Generated From?

You can also do it like following:

\DB::listen(function ($sql) {
            var_dump($sql);
        });

mshakeel started a new conversation OrderBy Resultset With Related Column

I have User model which has one Profile model.

/**
 * Get User's profile
 *
 * @return App/Models/Profile Profile object for this User
 */
public function profile()
{
    return $this->hasOne('App\Models\Profile');
}

Now I wanted to get all users order by profile.first_name. I have tried few options with no luck. Following is what I wanted:

$users = User::with('profile')->orderBy('profile.first_name')->get();

It says Unknown column 'profile.first_name'

Help me correct the way we can order by related model's column so I can further use it in my scopes:

/************************ Scopes *************************/

/**
 * Scope a query to get other users sorted by profile.first_name.
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function scopeOtherUsers($query)
{
    return $query->where('users.id', '<>', $this->id)
        ->with('profile')->orderBy('profile.first_name');
}
02 Oct
3 years ago

mshakeel left a reply on [L5] Disable CSRF Middleware On Certain Routes

In Laravel 5.1, you can exclude URIs from CSRF protection by simply adding them to the $except property of the VerifyCsrfToken middleware:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'api/*',
    ];
}

Documentation: http://laravel.com/docs/5.1/routing#csrf-protection http://stackoverflow.com/questions/26992885/laravel-5-post-whithout-csrf-checking/32902801#32902801