arifkhn46

arifkhn46

Member Since 1 Year Ago

New Delhi

Software Engineer at Incaendo Technologies Pvt. Ltd.

Experience Points 40,030
Experience Level 9

4,970 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 369
Lessons
Completed
Best Reply Awards 5
Best Reply
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.

03 Aug
10 months 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 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
11 months 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 miss '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 save() method:

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->collector()->save($collector);

}

Now we don't need method injection I think.

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
11 months 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->collector()->save($collector);

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

public function collectors()
{
    return $this->belongsToMany('App\Assignment')
            ->withTimestamps();
}
13 Jul
11 months 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
11 months 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
11 months 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 not 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('partnerGroups' => function ($query) {
    $query->select('id');
  }))->where('id', 2)->get()->first();
  $push = array();
  $partnerGroupIds = $check->partnerGroups->pluck('id')->toArray();
  $assigned = User::has('partnerGroups')
    ->whereHas('partnerGroups', function ($query) use ($partnerGroupIds) {
      $query->whereIn('id', $partnerGroupIds)->where('user_id', '!=', 2);
    })->get();

arifkhn46 left a reply on Distinct In Eloquent, Laravel.

@Hash you table has as you mentioned in your comment you have

1', '1' '1', '2' '2', '1' '2', '2' '2', '3'

You can see '2' '2' occurs two times, this could a reason for the issue.

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 What Is The Appropriate Way To Deal With User Roles?

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 `roles`.*, `role_user`.`user_id` as `pivot_user_id`, `role_user`.`role_id` as `pivot_role_id` from `roles` inner join `role_user` on `roles`.`id` = `role_user`.`role_id` where `role_user`.`user_id` = '1'

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