SachinAgarwal

SachinAgarwal

Technical Lead at ValueLabs

Member Since 4 Years Ago

Hyderabad

Experience Points
99,695
Total
Experience

305 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
582
Lessons
Completed
Best Reply Awards
43
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 20
99,695 XP
07 Nov
10 months ago

SachinAgarwal left a reply on A New Open Source Package For Google Places Api.

@RUSHVAN - replace use SKAgarwal\GoogleApi\PlacesApi; with use GooglePlaces;

03 Sep
1 year ago

SachinAgarwal left a reply on A New Open Source Package For Google Places Api.

@Mick79 Thanks for the input. I will try to write a blog to explain the usage.

And Yes you will have to Ajax the response.

17 Mar
2 years ago

SachinAgarwal left a reply on Model Count With A Condition As Per The Auth::user()->name

@kailash95 can you explain your requirement s bit more. Its unclear.

01 Mar
2 years ago

SachinAgarwal left a reply on Using Same Homestead Box After Upgrading Homestead To 5.0.1

@WebDo I read the doc. Tried same thing. After that I started getting this.

Anyways I have created new box and started using it. Thanks for your help.

SachinAgarwal left a reply on Using Same Homestead Box After Upgrading Homestead To 5.0.1

@WebDo I do not want to destroy the previous environment. I just want to use that environment with latest code base

SachinAgarwal started a new conversation Using Same Homestead Box After Upgrading Homestead To 5.0.1

I have upgraded the Homestead Box and Homestead code base. But now when I try to do vagrant up it tries to create new box and I get error saying

A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again

What I want is, when I do vagrant up it should use the previous box instead of creating new one.

Any help is appreciated.

28 Feb
2 years ago

SachinAgarwal left a reply on How To Make Middleware For Relationship?

@vipin93 that is exactly what @jacurtis said.

Auth::user() gives you current Login User. Who will have many students. Thus checking for Auth::user()->active == 1 gives you if the current login is user is active or not.

If your definition of current student is not current login user then please give a clarity about what is current student.

01 Feb
2 years ago

SachinAgarwal left a reply on A New Open Source Package For Google Places Api.

@TahaHameed Hi, I am not really sure if Google Places API actually support the reply to a review.

05 Jan
2 years ago

SachinAgarwal left a reply on Accessing Component's Data In Root Instance

@jaydeluca Thank you. This is exactly what I was looking for. :D

04 Jan
2 years ago

SachinAgarwal left a reply on A New Open Source Package For Google Places Api.

@Lelex974 @6ber6ou Please refer to the github link in the post. I have provided documentation. Thank you. :)

29 Dec
2 years ago

SachinAgarwal started a new conversation Accessing Component's Data In Root Instance

How can I access components data in my root vue instance?

component:
export default {
        data() {
            return {
                primaryTarget: 0,
                primaryActual: 0,
            }
        }
    }
Root instance:
import primarySalesBlock from "../components/primary_sales_block.vue";

new Vue({
         el: '#mdo-dashboard',
           
            
            components: {
                primarySalesBlockl
            },

    methods: {
                getFinanceData() { 
            console.log(this.primaryTarget)
        }
});
24 Dec
2 years ago

SachinAgarwal started a new conversation SQS Queue Driver Gives AWS.SimpleQueueService.NonExistentQueue

While using SQS queues i am getting this error:

Error executing "SendMessage" on "https://sqs.us-west-1.amazonaws.com/542241241453/trade-queue/third_party_api"; AWS HTTP error: Client error: `POST https://sqs.us-west-1.amazonaws.com/542241241453/trade-queue/third_party_api` resulted in a `400 Bad Request` response:
<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>A (truncated...)
AWS.SimpleQueueService.NonExistentQueue (client): The specified queue does not exist for this wsdl version. - <?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>AWS.SimpleQueueService.NonExistentQueue</Code><Message>The specified queue does not exist for this wsdl version.</Message><Detail/></Error><RequestId>f58be6b2-1d26-5dc3-83bc-b66ac865226e</RequestId></ErrorResponse>

Can anyone help me out here pls?

24 Nov
2 years ago

SachinAgarwal left a reply on Laravel Linux Error

@DarshanMalani Looks like you dont have php mysql extension installed. And I would suggest you to use homestead.

17 Nov
2 years ago

SachinAgarwal left a reply on How To OFF Laravel Error Massages

@Amalmax setting APP_DEBUG=false should do it. make sure you have .env file and not .env.example You will still see Opps something went wrong screen when there is a error

16 Nov
2 years ago

SachinAgarwal left a reply on How To OFF Laravel Error Massages

@Amalmax I was assuming the default error messages which laravel throws. If you are talking about different error messages please let us know with code example and a screenshot.

@martinbean I was assuming Laravel debug errors.

SachinAgarwal left a reply on Laracasts Refresh

@JeffreyWay

This is amazing! I loved it.

And I think 1 feature is missing.. since last logged in.

SachinAgarwal left a reply on Generate API Key On Registration

@thomasm789 You can use this package https://github.com/webpatser/laravel-uuid for generating Unique ID and you can create it in Creating model event like this

public static function boot() {
    parent::boot();

    static::creating(function($user) {
        $user->api_token = Uuid::generate();
    });
}

SachinAgarwal left a reply on How To OFF Laravel Error Massages

in your .env file set the debug=false

02 Jul
3 years ago

SachinAgarwal started a new conversation The Purpose Of Auth::viaRequest Method

What exactly is the purpose of Auth::viaRequest() method?

In Lumen it is used in authenticating user.

06 Jun
3 years ago

SachinAgarwal left a reply on Echo Method Result In Vue

@Ltloafer when you put @ blade ignores everything in it. It do not process any code

26 May
3 years ago

SachinAgarwal left a reply on How To Create Multi User System?

@pmall we still cant do Gate::guard()->denies();

SachinAgarwal left a reply on How To Make This An Eloquent Query?

@ Krenor probably it should be like this:

$jobs = Job::with(['applications.user.exam.subhect' => function($query){
        $query->where('subject_id', 3040);
    }])->where('tag', 10011015)->first();

SachinAgarwal left a reply on Creating Packages, Git And Github

@ ZetecVan Deploy it on packagist.org and install in your App using composer

SachinAgarwal left a reply on How To Create Multi User System?

@pmall 1 problem with guards is that it do not support Larave's Authorization Feature. Now suppose I need Different set of roles and permissions for different User types, How will I deal with that.?

SachinAgarwal left a reply on Prevent --force On Certain Publishes Tags?

@keogh There is not much you can do about it.

But 1 solution i will suggest is in your serviceprovider check if the file you want to publish is already exists and if it doesnt then the call $this->publishes();

Something like this:

private function publishModels()
{
    if(file_do_not_exists) {
        $this->publishes([
                __DIR__."/app/Models/Custom" => app_path("Cms"),
            ], "models");
    }
}

SachinAgarwal left a reply on Limited Number Of Files Per User

@bajro17

If each user can upload different number of images then store the limit in database.

Or if every user can upload only 5 pictures then have a global settings or use env or config And validate it with the count of images already uploaded. You can probably write a custom validator for it and use it for image uploads or do not even show upload field if the count of max uploads has reached.

23 May
3 years ago

SachinAgarwal left a reply on Npm Install Problem

@Tahsan I know i am late, but if u haven't got the solution yet, Then you have to install python and visual studio to make npm work on windows machine. Lately it had became this way since new version of npm.

09 May
3 years ago

SachinAgarwal left a reply on Conditional Query On Eloquent Instance.

@pmall No, that will make my Post model ugly. And this trait will be used to get the Feed for User. So The whole algo will be at 1 place. So this trait makes sense for me.

SachinAgarwal left a reply on Conditional Query On Eloquent Instance.

@pmall here you go.

<?php

namespace Janaspandana\Http\Services\Post;

use Janaspandana\Department\Department;
use Janaspandana\Grievance\Grievance;
use Janaspandana\Post\Post;
use Janaspandana\User\User;

/**
 * trait UsersFeed
 *
 * Get the Feed for given User.
 *
 * @author Sachin Agarwal <sachinkumaragarwal05@gmail.com>
 * @package Janaspandana\Http\Services\Post
 */
trait UsersFeed
{
    /**
     * @var \Janaspandana\Post\Post
     */
    protected $postBuilder;

    public function bootUsersFeed()
    {
        $this->postBuilder = new Post;
    }

    /**
     * Get the Feed For User.
     *
     * @param \Janaspandana\User\User $user
     *
     * @return \Janaspandana\Post\Post
     */
    public function getUserFeed(User $user)
    {
        $this->bootUsersFeed();

        $this->whereFollowedUsersFor($user);

        $this->whereFollowedDepartmentsFor($user);

        return $this->getPosts();
    }

    /**
     * @param \Janaspandana\User\User $user
     *
     * @return mixed
     */
    protected function getFollowedUserIds(User $user)
    {
        $followedUserIds = $user->followedUsers()->pluck('following_id');

        $followedUserIds[] = $user->id;

        return $followedUserIds;
    }

    /**
     * Add clause to get Followed Users.
     *
     * @param \Janaspandana\User\User $user
     */
    protected function whereFollowedUsersFor(User $user)
    {
        $followedUserIds = $this->getFollowedUserIds($user);

        $this->postBuilder->whereIn('user_id', $followedUserIds);
    }

    /**
     * @param \Janaspandana\User\User $user
     *
     * @return mixed
     */
    protected function getFollowedDepartments(User $user)
    {
        return $user->followedDepartments;
    }


    /**
     * @param \Janaspandana\User\User $user
     */
    protected function whereFollowedDepartmentsFor(User $user)
    {
        $followedDepts = $this->getFollowedDepartments($user);

        if ($followedDepts->isEmpty()) {
            return;
        }

        foreach ($followedDepts as $department) {
            $types = $this->preparePostTypesForDepartment($department);

            $this->addScopeForDepartment($department, $types);
        }
    }

    /**
     * @param \Janaspandana\Department\Department $department
     *
     * @return array
     */
    protected function preparePostTypesForDepartment(Department $department)
    {
        $types = [];

        $followedItems = $department->pivot_items;

        if (!empty($followedItems)) {
            foreach ($followedItems as $item => $value) {
                $types[] = config('follows.department.items_classes')[$item];
            }
        }

        return $types;
    }

    /**
     * @param \Janaspandana\Department\Department $department
     * @param array $types
     */
    protected function addScopeForDepartment(Department $department, $types)
    {
        if (empty($types)) {
            return;
        }

    // This is scope on Post model
        $this->postBuilder->departmentsForFeed($department->id, $types);
    }

    /**
     * Get the Posts.
     *
     * @return \Janaspandana\Post\Post
     *
     */
    public function getPosts()
    {
        return $this->postBuilder->latest()->paginate(5);
    }
}

SachinAgarwal left a reply on Conditional Query On Eloquent Instance.

@pmall Not really sure if that is what I am doing. I have big complex algorithm here, which add some where clauses to the Post model depending on some conditions.

SachinAgarwal started a new conversation Conditional Query On Eloquent Instance.

I am trying to New up a n eloquent instance and add the query conditionally later like this.

trait SomeTrait {
    protected $postBuilder;
    
    public function bootUsersFeed()
    {
        $this->postBuilder = new Post;
    }

    public function someFunction(User $user)
    {
        $this->bootUsersFeed();

        // This is just sample, I am doing more if this kind of stuff.
        $this->postBuilder->where('user_id', $user_id);

        return $this->getPosts();
    }

    public function getPosts()
    {
        return $this->postBuilder->latest()->paginate(5);
    }
}

But I get all the posts. The where clause it not even applying.

Any help will be appreciated. Thank You :)

04 May
3 years ago

SachinAgarwal started a new conversation Storing JSON Type On Pivot Table Of Polymorphic Many To Many Relation

I am having a polymorphic many to many relation set up. And i have a extra column called items on the pivot table. Now this column is JSON type. And Normal Storing and retrieving is working fine.

Now how do I tell Eloquent that this column of pivot table is JSON type.?

Currently I have to do json_encode and json_decode manually like this.

    $items = json_encode(['grievance' => true]);
    $user->followedDepartments()->attach($dept, ['items' => $items]);

    $items = json_decode($dept->followers()->first()->pivot->items);
    dd($items->grievance);

And if i do it like this:

    $items = ['grievance' => true];
    $user->followedDepartments()->attach($dept, ['items' => $items]);

    $items = $dept->followers()->first()->pivot->items;
    dd($items['grievance]);

I get following error.

    preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

I have found this link and tried the solution, But not working.

Does anyone know how to achieve this?

21 Apr
3 years ago

SachinAgarwal left a reply on Loggin Custom Exceptions

@RoboRobok the sending sms code in a event handler which will be under queue. And yes, it makes sense, not to throw exception at all. Just log instead of throwing exception.Ty :D

SachinAgarwal started a new conversation Loggin Custom Exceptions

What I am trying to do is,

  • Send an sms to a number (this is a queued process);
  • If there a error response from the sms api, I throw an SMSException
  • Now I just want to log the error and continue with next steps instead of halting the execution.

I know about Handler.php. But doesnt seem to continue the execution. I can do this

try{
} catch (SMSException $e) {
}

But then every time I throw an exception for it, I have to do this. That means i have to repeat it which is what i am trying to avoid. Any other way I can achieve this.

20 Apr
3 years ago

SachinAgarwal left a reply on Learning Laravel On Windows System

@khazon I develop on windows. And I have up and running homestead. There is no problem in laravel development in windows. :D

19 Apr
3 years ago

SachinAgarwal left a reply on Is This Right ?

@cyholder you can refactor most of the stuff. plus, u r using rand() function for fine name, that will eventually will cause name to repeat, which will either cause error or replace the old image. use microtime() so it will never be same name.

18 Apr
3 years ago

SachinAgarwal left a reply on Redirect To Another View

@Slillz your method is post it should be get.

14 Apr
3 years ago

SachinAgarwal started a new conversation Homestead Ports Config Windows

The problem is, I am up and running with vagrant with homestead box perfectly on my windows 10 machine. In my yaml file I added 6379 port forwarding for redis. And when I check the open ports I can see 0.0.0.0:6379 Listening. But I am not able to run any command from the cmd for the project. Like if I run php artisan migrate I get this error.

[Predis\Connection\ConnectionException]
  Error while reading line from the server. [tcp://localhost:6379]

Unable to understand the prob. (edited)

06 Apr
3 years ago

SachinAgarwal left a reply on Setting Storage Engine Globally

@ohffs Yes, I want to make sure its always InnoDB.

And yes, I am aware of Blueprint class. That was my question, If I do it with Blueprint class, I have to add it to every migration file. So I was wondering if I can just set this at one place only and not have to do it in every migration file.

SachinAgarwal left a reply on Setting Storage Engine Globally

@ohffs Databse storage engines. like InnoDB , MyISAM etc.

SachinAgarwal started a new conversation Setting Storage Engine Globally

Is there a way to set the database storage engine globally like in config file or somewhere?

Its little hectic to set the storage engine in each migration file.

19 Mar
3 years ago

SachinAgarwal started a new conversation Lesson On Using Vue Router With Laravel

A lesson using vue-router with laravel will be really useful.

04 Mar
3 years ago

SachinAgarwal left a reply on Dd() Is Giving Some Weird Text.

@imansyaefulloh That was my custom helper file. It doesnt ship with laravel. If you are facing same problem then probably you have an empty file which is having only <?php tag in it. Just identify the file and delete it if its no use.

25 Feb
3 years ago

SachinAgarwal left a reply on Dispatch Model Events Manually

@usman you mean $modelObj->fireModelEvent('created');

SachinAgarwal started a new conversation Dispatch Model Events Manually

Is there a possibility to dispatch model events manually?
What I am trying to do is, Fire created event when I save model with save() method.

08 Feb
3 years ago

SachinAgarwal started a new conversation A New Open Source Package For Google Places Api.

I made A new Open source package for Google Places Api. which is Laravel Friendly.

I will be glad to hear the feedback.

https://github.com/SachinAgarwal1337/google-places-api