mihirpatel83

mihirpatel83

Member Since 9 Months Ago

Experience Points
3,600
Total
Experience

1,400 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
24
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
3,600 XP
Oct
15
5 days ago
Activity icon

Started a new Conversation Messaging Like Facebook

I am trying to develop something which is a basic version of Facebook Messaging. I.e. a page where you have users on left and their messages on right.

I was wondering should I create different channel for each conversation with different users? Lets say I have 3 friends User2, User3, User4, User5 so should I create and listen to 4 private channels as below which will listen only on Chat page.

"PrivateChannel_User1_User2", "PrivateChannel_User1_User3", "PrivateChannel_User1_User4", "PrivateChannel_User1_User5"

or

Should I just create and listen to a global single "PrivateChannel_User1" which will listen to all kinds of events be it message or any other notification?

Currently, I have implemented the first way but it is giving me problems like on Chat page I register listener which are my friends but any new friend or messages from him will not be known. I will have to refresh page again.

Basically interested in knowing the proper approach on going ahead which such kind of application.

Oct
10
1 week ago
Activity icon

Replied to Register In Multiple Channels Laravel Echo

How did you went ahead with it? I am also wondering the same as I am trying to implement facebook messaging. So do i need to listen to no. of channel equal to no. of my friends.

In the sample that I implemented, I create a private channel between two users by taking the sender and receiver id as identifier.

Activity icon

Replied to Peer To Peer Chat - Channel Name

I am talking about creating a unique channel for two users. For ex. User 1 and User 2 are there and User 1 sends message to User2 then it will create channel as chat-message-1-2 and User 2 sends message to User 1 then it will create channel as chat-message-2-1

so User 1 will not get message from User2 and viceversa. How to avoid this situation? Not sure how your suggestion will help.

Thanks.

Activity icon

Started a new Conversation Peer To Peer Chat - Channel Name

I am currently working on to learn real time chat and I created a private channel named "chat-message" but it can be listened by all authenticated users.

So I have to name the channel as unique which only two users knows. Naming something as chat-message-sender_id-receiver_id will not work as it will create two different channels.

How can I create and identify a unique channel between two users?

Oct
09
1 week ago
Activity icon

Replied to Laravel Broadcasting - Preferable Way To Go

Thank you for updating me on this but I guess being a newbie both with VueJS, Laravel it was too much for me to learn and setup the socket.io/websockets, redis etc.

With time, I will definitely not want to use Pusher but as of now going ahead with Pusher so that I can concentrate on basic concepts and VueJS as well. Once i learn to implement I will go ahead and try and remove Pusher dependeny from code.

Oct
08
1 week ago
Activity icon

Replied to Understanding Package.Json

@audunru - Thank you for clarifying.... I kinda get it now which is Laravel way and which is not. I think I will follow using webpack.

@sinnbeck - Didn't knew about Envoy. Seems promising. Thanks for drawing attention towards it.

Oct
07
1 week ago
Activity icon

Replied to Understanding Package.Json

Thanks for reverting. Using webpack to create bundle will even result in not installing any of the NPM packages on the server. That I understand.

But just in case, Should I choose not to use webpack then I will have to use package-lock.json to install required packages on server. But to create that file on my development server, I will first have to move all required dependencies under "dependencies" then do "npm update" which will update package-lock.json and then I can use this file on production server. I think this is the way these work but just wanted to be sure of.

Oct
04
2 weeks ago
Activity icon

Started a new Conversation Understanding Package.Json

Below is dependencies in package.json file on my development server for a project. So basically these generates a package-lock.json which I have to commit on production server and which will install same dependencies on it.

Will the dependencies mentioned in "devDependencies" be included on production server? I guess no. If so then it means before I move project to production server I have to move/copy dependencies from "devDependencies" to "dependencies" and update the package-lock.json.

Please correct If my understanding is not correct and If there is any reference article which tells the correct procedure or steps for using the node packages from development to production.

 "devDependencies": {
        "axios": "^0.18.1",
        "cross-env": "^5.1",
        "laravel-mix": "^4.0.15",
        "lodash": "^4.17.15",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue-template-compiler": "^2.6.10"
    },
 "dependencies": {
        "laravel-echo": "^1.6.1",
        "pusher-js": "^5.0.2",
        "vue": "^2.6.10"
    }
Oct
03
2 weeks ago
Activity icon

Replied to Laravel Broadcasting - Preferable Way To Go

Seems a great one. Will go through it and start implementing to learn.

Pusher is a paid one so wondering which of the other two options will be great to implement performance wise?

Activity icon

Replied to Service Provider Not Updating After Redirecting

Gotcha.... Thanks for explaining.

Oct
02
2 weeks ago
Activity icon

Replied to Service Provider Not Updating After Redirecting

There is a "Read All Notification" button on the notification panel, clicking on which it redirects to a GET call i.e. index function of Notification controller and where I was marking notifications as read and fetching them again.

So I will have to redirect to a different route which marks as read all the notification and then redirect to the index function which fetches the notifications.

Right?

Activity icon

Started a new Conversation Laravel Broadcasting - Preferable Way To Go

I would like to implement some realtime functionalities like notifications or chat. The more I search the more it's confusing me.

You can use pusher, redis, nodes.js. laravel-websockets, ratchet. I guess there different ways to do this

  1. Laravel & Pusher and this way you don't have to implement the websockets server
  2. Laravel + Redis + socket.io
  3. Laravel websockets(Based on Ratchet)

I am thinking to start implementing with Laravel and Pusher and then once done think about implementing own server with nodejs or laravel websockets package.

Just wondering If my understanding is right and it's the right way to go for. I am totally a newbie and would like suggestion on selecting a proper approach to learn and implement this.

Activity icon

Started a new Conversation Service Provider Not Updating After Redirecting

I have created a NotificationServiceProvider and using ViewComposer displays the count and list of unread notifications by injecting viewcomposer in navigation layout. Let's say the total unread is 11.

@include('composers.notification')

Now I have created a NotificationController where in I have written below statements which marks all notifications as read and then fetch them and display in the view.

 auth()->user()->unreadNotifications->markAsRead();
 $notifications = auth()->user()->notifications;
 return view('notifications.index', compact('notifications'));

When I click "Read All Notifications" on notifications panel, it redirects to notification listing page and displays all the notifications. However, the count still shows 11. I guess this is because the ServiceProvider code is executed first and then the code in controller.

One solutions is I mark notifications with an ajax call and then redirect to the notifications listing page.

Is this the correct way or there exist a better solutions?

Activity icon

Started a new Conversation ServiceProvider Named As One Of The Default Provider

I have created an application service provider named as PipelineServiceProvider and was not thrown any error on registered it as "App\Providers\PipelineServiceProvider::class"

Recently I found out that there already exists a framework service provider as "Illuminate\Pipeline\PipelineServiceProvider::class"

Just wondering if two service provider with same name will cause any problem?

Sep
25
3 weeks ago
Activity icon

Replied to Different Validation Rules For Different Methods?

Just an example of how I use in a Form Request

public function rules() {
    switch ($this->method()) {
            case 'POST': {
                    $rules = [ //Define your rules ];
                    break;
                }
            case 'PATCH': {
                    $rules = [//Define your rules ];
                    break;
                }
        }
}
Activity icon

Replied to Super Function For Json Response

Do you mean something like this. Not sure If you are referring to something like this.

https://laravel.com/docs/5.8/eloquent-mutators#attribute-casting

You can access the json object as an array.

Sep
24
3 weeks ago
Activity icon

Started a new Conversation Including/Excluding A Functionality Based On Permissions

I have different entities in my system. Like Customer, Project, Product, Events etc

Now, there is pipeline entity and the instance name is "Sample Pipeline" and with different stages "High", "Medium", "Low".

Now, different entity instances will be assigned to stages of "Sample Pipeline". So whenever I create/edit instance of each entity, I will have a dropdown to select the pipeline and the ajax will display another dropdown with stages. Upon saving the instance, I will attach the instance with a stage of pipeline.

I was wondering how or what functionality of laravel will be helpful so that I don't have to go and add the code in each controller, view of all entities. The code once created can be easily injected. Is this achieved with dependency injection or facades or something else as simple as widget or what?

Just need help with knowing how a functionality can be created once and can be injected or removed anytime. A reference links to understand a suggested functionality will be great.

Thanks.

Aug
15
2 months ago
Activity icon

Started a new Conversation Parameterized With IN Operator In WhereRaw

Below is a working code for searching using IN operator

$strwq = "'" . implode("','", array_map('strtolower', $searchId)) . "'";
$query->whereRaw("lower(attributes->>'$.\"2\".value') IN (" . $strwq . ")");

But when I try couple of ways to change the above query to parameterized, it just don't work. No error thrown and no records returned.

$strwq = "'" . implode("','", array_map('strtolower', $searchId)) . "'";
$query->whereRaw("lower(attributes->>'$.\"2\".value') IN (?)",[$strwq]);
$query->whereRaw("lower(attributes->>'$.\"?\".value') IN (?)",[2,$strwq]);

$strwq = implode("','", array_map('strtolower', $searchId));
$query->whereRaw("lower(attributes->>'$.\"2\".value') IN ('?')",[$strwq]);

$strwq = implode(",", array_map('strtolower', $searchId));
$query->whereRaw("lower(attributes->>'$.\"2\".value') IN (?)",[$strwq]);
Aug
13
2 months ago
Activity icon

Replied to Passing Object To Function Not Typecasting

I will try to explain it in detail. I have a ProjectController and one of the action has code as below

foreach ($listAttributes AS $attribute) {  
            if(isset($project->attributes[$attribute['id']])){
                $col = 'col' . $attribute['id'];
                $val[]= $project[$col];            
            }   
        }

printing $project->attributes variable here before the for loop will give result as below. It basically returns the typecasted value of json field to array and where "attributes" is the json field of table.

Array ( [1] => Array ( [value] => Test ) [2] => Array ( [value] => 1 ) [3] => Array ( [value] => 2 ) [4] => Array ( [value] => 2 ) [5] => Array ( [value] => 2019-07-25 ) [6] => Array ( [value] => 2019-07-25 ) [7] => Array ( [value] => 15 ) [8] => Array ( [value] => ) [10] => Array ( [value] => 50 ) [12] => Array ( [value] => Array ( [0] => 1 ) ) ) 

Now like Project, I have many entities and each have an "attributes" field in database like Product, Event etc.

So I changed above code to

function getEntityValues($listAttributes,$entity){
    $tmp=[];
    foreach ($listAttributes AS $attribute) {  
        if(isset($entity->attributes[$attribute['id']])){
            $col = 'col' . $attribute['id'];
            $tmp[]= $entity[$col];            
        }   
    }
    return $tmp;
}   

which can be called like $val = Entity::getEntityValues($listAttributes,$project); //Project entity $val = Entity::getEntityValues($listAttributes,$event); //Event entity

Now, when I print $entity->attributes in the above function It returns

Array ( [id] => 1 [attributes] => {"1": {"value": "Test"}, "2": {"value": "1"}, "3": {"value": "2"}, "4": {"value": "2"}, "5": {"value": "2019-07-25"}, "6": {"value": "2019-07-25"}, "7": {"value": "15"}, "8": {"value": null}, "10": {"value": "50"}, "12": {"value": ["1"]}} ) 

This you can see that is a list of all fields returned in a collection and not just the "attributes" field. Now, If i change the attributes field in database to something else for eg "properties" then everything works fine but it's the issue only when the name of the field is "attributes". Is it because there is already a "attributes" property in collection?

Just trying to figure If is probably due to using any reserve word in Laravel like "attributes". If yes, then which are the other list of names that are reserved? I didn't find any such list though.

Aug
12
2 months ago
Activity icon

Started a new Conversation Passing Object To Function Not Typecasting

I have a project model object where in there is a json field named as "attributes". When I print_r($project->attributes), It prints the typecasted array of attributes(MySql column) field as below:

Array ( [1] => Array ( [value] => Test ) [2] => Array ( [value] => 1 ) [3] => Array ( [value] => 2 ) [4] => Array ( [value] => 2 ) [5] => Array ( [value] => 2019-07-25 ) [6] => Array ( [value] => 2019-07-25 ) [7] => Array ( [value] => 15 ) [8] => Array ( [value] => ) [10] => Array ( [value] => 50 ) [12] => Array ( [value] => Array ( [0] => 1 ) ) ) 

But when I pass the same object $project to a function and print_r($project->attributes) then it displays all the fields of the tables.

Array ( [id] => 1 [attributes] => {"1": {"value": "Test"}, "2": {"value": "1"}, "3": {"value": "2"}, "4": {"value": "2"}, "5": {"value": "2019-07-25"}, "6": {"value": "2019-07-25"}, "7": {"value": "15"}, "8": {"value": null}, "10": {"value": "50"}, "12": {"value": ["1"]}} ) 

Why is this happening? Changing the field name from "attributes" to anything else like "attributes1" then it works properly.

Jun
26
3 months ago
Activity icon

Replied to Search Word Within JSON Field

Below query works at the moment as per my requirement. "attributes" is the name of the JSON field and I had numeric keys within it.

Customer::select(DB::raw('CONCAT(id,"_","Customer") AS iid'), DB::raw('attributes->>"$.\"1\".value" AS text'))->whereRaw('JSON_SEARCH(attributes, "all", "John") IS NOT NULL')->get();

Also, some of the query example that worked and might be helpful to someone

Customer::whereJsonContains('attributes->1->value', 'John')->get();

Customer::whereRaw('JSON_CONTAINS(attributes->"$.\"1\".value", \'"John"\')')->get();
Activity icon

Replied to Search Word Within JSON Field

@AURAWINDSURFING - That is not going to help as I have to search for Customer and list them out based on the searched string. so it should be the mysql query only that will help. Thank you for suggestion.

Jun
25
3 months ago
Activity icon

Started a new Conversation Search Word Within JSON Field

I am storing values in a JSON field in below format

{
   "1":{
      "value":"John"
   },
   "2":{
      "value":"Canada"
   },
   "3":{
      "value":[
         "Java",
         "Dot Net"
      ]
   },   
   "5":{
      "value":"Male"
   },
   "6":{
      "value":[
         "Sports",
         "Dancing"
      ]
   }
}

How can I search for a word "Male" or "Toronto" or use wild card operators with the query?

I tried but didnt worked.

  • Customer::whereRaw('JSON_CONTAINS(attributes->"$[*]", "male")')->get();
  • Customer::whereRaw('JSON_CONTAINS(attributes->"$[*].value", "male")')->get();

Below worked but needs the key to be dynamic or can use wildcard with values.

  • Customer::whereJsonContains('attributes->1->value"', 'John')->get();
Jun
21
3 months ago
Activity icon

Replied to JSON Field Order Changes While Saving

@ATHAKUR - Yes I read that and which essentially is not the way most usecases want that. Hence want to know a workaround for that.

One thing is storing some kind of extra ordering no with each value but that will be extra work to parse it. That's the solution I can think of at the moment.

Activity icon

Replied to JSON Field Order Changes While Saving

@ATHAKUR - I am using casting only but I guess the link doesn't answers my question. The order gets changed on saving which I don't want. Need to know a way to maintain the order of the values that are stored.

Activity icon

Started a new Conversation JSON Field Order Changes While Saving

I am using a json Field to store multiple values of a dropdown. The array is like

["Male"=>"Male","Female"=>"Female","Test"=>"Test"]

but when I check the values in database after saving in JSON field it is of below format.

{"Male": "Male", "Test": "Test", "Female": "Female"}

Upon searching a bit it seems that MySql sorts them. What could be a possible solution to overcome these?

Jun
14
4 months ago
Activity icon

Replied to Model Function Within FormRequest

@MANELGAVALDA - I tried to validate in controller because I didnt knew how to access the model. But now it's working great with your solution so will not bother checking out the validation issue in controller. Thank you for your time :)

Activity icon

Replied to Model Function Within FormRequest

Another Issues with the same is , When I use below code in controller validation is not fired.

$rules = $request->rules();
$rules["attributes.1.value"] = 'required';
$validator = Validator::make($request->all(), $rules);

But when I write below rule in ProductFormRequest then it works? Not sure what am I doing wrong.

$rules["attributes.1.value"] = 'required';
Activity icon

Replied to Model Function Within FormRequest

@MANELGAVALDA - Great...Thank you.

Activity icon

Started a new Conversation Model Function Within FormRequest

How can I call a model function within FormRequest? I have rules function in ProductFormRequest where I set the rules for validation. Now I have used a JSON field to add custom attributes for products. I want to validate those attributes and for which I need to read the JSON from attributes field of Product table in ProductFormRequest or may be able to access product object somehow?

Jun
10
4 months ago
Activity icon

Replied to Laravel ToArray Changing Id From String To Integer

@CRONIX - Yes Indeed to Array is the issue. I am sending just one id field but I guess either I will have to typecast id field to string or as you said loop through and create array without using "toArray". Thank you.

Activity icon

Replied to Laravel ToArray Changing Id From String To Integer

@JLRDW - Casting did worked but wondering why toArray or toJson force it to typecast to Integer. I am not sure if casting will be affecting anywhere else where I am using Product Object. Thank you.

Activity icon

Replied to Laravel ToArray Changing Id From String To Integer

@JLRDW - Wish I could do that. But I am using Select2 where I have to return values as Json data with keys id and text i.e.

{"id":"125_Product","text":"asdf5"}

Activity icon

Started a new Conversation Laravel ToArray Changing Id From String To Integer

Hello all,

I am executing a query like below:

$allProducts = \App\Product::select('id', DB::raw('CONCAT(id,"_","Product") AS id'), 'title as text')->where('title', 'like', "%$search%")->get();

It has array of values for eg: "id=125_Product" and "name=TestProduct" but when I want the values in array and do $allProducts->toArray() the "_Product" which I have appended to the id field gets stripped and the id key in array holds only integer value.

How can I resolve this?