arifkhn46

arifkhn46

Member Since 2 Years Ago

New Delhi

Software Engineer at Incaendo Technologies Pvt. Ltd.

Experience Points 42,650
Experience Level 9

2,350 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 395
Lessons
Completed
Best Reply Awards 5
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.

02 Sep
2 weeks ago

arifkhn46 commented on Explain PHP Generators

What are the cons of the generator approach?

30 Jul
1 month ago

arifkhn46 left a reply on Using Valet With Subfolders?

This trick works well, I would recommend this answer as best answer.

03 Aug
1 year ago

arifkhn46 left a reply on Profile Changes Approve/reject - Keep The Current As Active

I think you need to keep the user history. Watch Build an Activity Feed: Part 1 or How to Construct an Activity Feed with TDD Part I & Part II lesson and you will get the idea of how can you build such a thing.

And I think Activity Log might help you to achieve this task.

15 Jul
1 year ago

arifkhn46 left a reply on Relationship Does Not Work

@pickab00 Please refer official docs

https://laravel.com/docs/5.6/eloquent-relationships

It says

If you need even more power, you may use the whereHas and orWhereHas methods to put "where" conditions on your has queries. These methods allow you to add customized constraints to a relationship constraint, such as checking the content of a comment:

// Retrieve all posts with at least one comment containing words like foo%
$posts = App\Post::whereHas('comments', function ($query) {
    $query->where('content', 'like', 'foo%');
})->get();

So I think you can write query like:

$latest = Category::whereHas('articles', function ($q){
        $q->where('lang', '=', '1');
        $q->where('approved', '=', '1');
    })->get();

arifkhn46 left a reply on Inserting Many To Many Relationship Tables In One Create Blade Form Laravel 5.4

@jec360 Your Welcome! Please mark my first comment as best reply, it will help others to find the solution easily. ;)

arifkhn46 left a reply on Laracasts Refresh

Simple and perfect :)

arifkhn46 left a reply on Where Are You All From?

New Delhi, India!

arifkhn46 left a reply on React.js And Laravel Together

I think yes read Tylor's blog:

https://medium.com/@taylorotwell/laravel-frontend-presets-eca312958def

You can easily configure the react.js in your laravel project.

But you can get resources/tutorials of Vue.js and Laravel easily on the internet.

arifkhn46 left a reply on Inserting Many To Many Relationship Tables In One Create Blade Form Laravel 5.4

@jec360 I think you missed 's' in collector()

 $assignment->collector()->save($collector);

it should be

 $assignment->collectors()->save($collector);

arifkhn46 left a reply on Inserting Many To Many Relationship Tables In One Create Blade Form Laravel 5.4

@jec360 use create() instead of method save():

public function store(Request $request)
{
    $this->validate($request, [
        'area_id' => 'required',
        'mts_id' => 'required',
        'status' => 'required',
        'collector_id' => 'required'
    ]);

     $assignment = App\Assignment::create($request->only([
        'area_id',
        'mts_id',
        'status'
    ]));

    $collector = App\Collector::find($request->collector_id);
    $assignment->collectors()->save($collector);

}

Now you don't need the method injection, I think.

I am updating my previous comment also.

arifkhn46 left a reply on Inserting Many To Many Relationship Tables In One Create Blade Form Laravel 5.4

The reason behind this exception could be the area_id is not passing to the save() function, try dumping the request array and check the area_id is present or not :

dd($request->only([
        'area_id',
        'mts_id',
        'status'
    ]));
14 Jul
1 year ago

arifkhn46 left a reply on Inserting Many To Many Relationship Tables In One Create Blade Form Laravel 5.4

@jec360 Try following code :

In the store method you don't need App\AssignmentCollector class it is unecessary, instead you need App\Collector():

    $this->validate($request, [
        'area_id' => 'required',
        'mts_id' => 'required',
        'status' => 'required',
        'collector_id' => 'required'
    ]);

    $assignment = new Assignment();
    $assignment->area_id = $request->area_id;
    $assignment->mts_id = $request->mts_id;
    $assignment->status = $request->status;
    $assignment->save();

    $collector = App\Collector::find($request->collector_id);
    $assignment->collectors()->save($collector);

And in Collector.php the relationship collectors is wrong it should be:

public function assignments()
{
    return $this->belongsToMany('App\Assignment')
            ->withTimestamps();
}

Also you can use the method injection instead in your store method, you don't need to new up the Assignment class manually.

public function store(Request $request)
{
    $this->validate($request, [
        'area_id' => 'required',
        'mts_id' => 'required',
        'status' => 'required',
        'collector_id' => 'required'
    ]);

    $assignment = App\Assignment::create($request->only([
        'area_id',
        'mts_id',
        'status'
    ]));

    $collector = App\Collector::find($request->collector_id);
    $assignment->collectors()->save($collector);

}
13 Jul
1 year ago

arifkhn46 left a reply on Undefined Index: Features

@Hourlee

Suppose I have following array:

$array = array(
  'key1' => 'value1',
  'key2' => 'value2',
  'key3' => 'value3,
  'key4' => 'value4',
);

Now if I will access anything which is not a key in php $array will produce Undefined index: like

$array['uknown']
12 Jul
1 year ago

arifkhn46 left a reply on Undefined Index: Features

Hi,

Please make sure each $row in $rows having features key in it. This generally occurs only when we try to access the key which is not present in the array.

arifkhn46 left a reply on Laravel File Storage: How To Store (decoded) Base64 Image?

@DoeJohn You can try something like this:


$base64_image = "data:image/jpeg;base64, blahblahablah";

if (preg_match('/^data:image\/(\w+);base64,/', $base64_image)) {
    $data = substr($base64_image, strpos($base64_image, ',') + 1);

    $data = base64_decode($data);
    Storage::disk('local')->put("test.png", $data);
    dd("stored");
}

11 Jul
1 year ago

arifkhn46 left a reply on Redirecting Back On Validation Error Instead Of 422 JSON

404 page means the url you are requesting is does not exist, please make sure the url is correct.

arifkhn46 left a reply on Distinct In Eloquent, Laravel.

@Hash Your Welcome! On my local I setup it with partnerGroups, that's why the typo left in the code, btw I have updated the code in the comment.

arifkhn46 left a reply on Distinct In Eloquent, Laravel.

@toby Yeah! you are right there is no problems in the data in the table partner_group_user,.

arifkhn46 left a reply on Distinct In Eloquent, Laravel.

@Hash try following code:

  $check = User::with(array('partner_groups' => function ($query) {
    $query->select('id');
  }))->where('id', Auth::id())->get()->first();

  $partnerGroupIds = $check->partner_groups->pluck('id')->toArray();

  $assigned = User::has('partner_groups')
    ->whereHas('partner_groups', function ($query) use ($partnerGroupIds) {
      $query->whereIn('id', $partnerGroupIds)->where('user_id', '!=', Auth::id());
    })->get();

Here you can use distinct clause also in case of duplicate results.

arifkhn46 left a reply on Distinct In Eloquent, Laravel.

I setup things on local in the same manner as you described and I used the same code that you have pasted in this post, and its just working fine, I am not getting any duplicate records.

user ids:

array:7 [▼
  0 => 16
  1 => 21
  2 => 81
  3 => 83
  4 => 88
  5 => 92
  6 => 99
]

And here is the raw query:

select * from `users` where exists (select * from `partner_groups` inner join `user_partner_groups` on `partner_groups`.`id` = `user_partner_groups`.`partner_group_id` where `users`.`id` = `user_partner_groups`.`user_id`) and exists (select * from `partner_groups` inner join `user_partner_groups` on `partner_groups`.`id` = `user_partner_groups`.`partner_group_id` where `users`.`id` = `user_partner_groups`.`user_id` and `id` =  10 and `user_id` != 2

arifkhn46 left a reply on Distinct In Eloquent, Laravel.

What is the relationship between users and partners_group table?

arifkhn46 left a reply on Is Vue A Competitor For Laravel?

No! Vue.js and Laravel are friends. ;)

15 Oct
1 year ago

arifkhn46 started a new conversation Users Role Check, Repeated Query Issue.

Hi,

I am developing an application which is Role based system. So I am trying to know what is the Laravel way to deal with following problem:

I've been using this method of checking for role Auth::user()->hasRole('admin'), throughout my layout and view files.

It was only until I installed Laravel Debugbar that I realise there were multiple repeated database queries. For instance, 19 statements were executed, 18 of which were duplicated, 1 unique

Most of them were:

select exists(select * from `roles` inner join `role_user` on `roles`.`id` = `role_user`.`role_id` where `role_user`.`user_id` = '1' and `id` = '1') as `exists`

So here I want to know how to solve this repeated query problem, what is the laravel way.