gitwithravish

Full Stack Developer at Unocoin

Member Since 1 Year Ago

Bangalore, India

Experience Points
67,000
Total
Experience

3,000 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
309
Lessons
Completed
Best Reply Awards
43
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 14
67,000 XP
Feb
03
3 weeks ago
Activity icon

Started a new Conversation Any Good Way To Organise Localisation Files?

I want to organise locale files stored in resources/lang/en for different api versions and within that for different modules/categories.

Any good practices or tips?

Feb
02
3 weeks ago
Activity icon

Started a new Conversation How To Automatically Restart A Console Command If It Dies

I am running multiple console commands in production. Some commands including jobs processor dies somehow. I want to restart that process if it dies.

What could be a clean way to do this?

Jan
12
1 month ago
Activity icon

Replied to How Can I Add Flash Message In Delete Action?

what about the second option?

session()->flash(...)
Activity icon

Replied to How Can I Add Flash Message In Delete Action?

Laravel autoload the session facade, you can see it in app.php. You can directly import it like this.

use Session;

Session::flash('key','value');

Or you can use the accessor

session()->flash('key','value');
Activity icon

Replied to How Can I Add Flash Message In Delete Action?

\Session::flash('key','value');
Jan
06
1 month ago
Activity icon

Replied to Accessing Related Model In Boot Method

Can you provide some context so that I can understand better and suggest accordingly ?

When and in what scenario are you using this code snippet and with what model and relationship?

Jan
02
1 month ago
Activity icon

Replied to Inertia Js Vue Laravel Accordion

Its not difficult to do. All you have to do is

  • Add an event listener for when someone click on accordion header,
  • Make ajax call to get json data or html data
  • Load that data within accordion and open it

You can also show a spinner or loader gif or something like that so that the user gets a feedback that something is being loaded from the server, otherwise he might keep clicking on the header, resulting into unnecessary ajax requests.

There are other ways as well

Search How to load dynamic data/components in vue

Activity icon

Replied to Accessing Related Model In Boot Method

I don't know what exactly you are trying to do, but usually you wanna use an event inside booted() method, depending on the purpose of your code. For example,

protected static function booted()
{
    parent::booted();
    self::retrieved(function($model){
        $model->relationName->id;
    });
}

List of events

https://laravel.com/docs/7.x/eloquent#events

Usage example

https://laravel.com/docs/7.x/eloquent#events-using-closures

Dec
31
1 month ago
Activity icon

Started a new Conversation Get Eloquent Model With ALL Relationship Models

Is there any way to fetch model with all its relationships without needing to mention every single one of them within with() method?

Dec
29
1 month ago
Activity icon

Replied to Duplicate Submit When Browser Back After Login

Do you mind explaining the purpose of such approach?

Activity icon

Replied to How To Debug Wrong Matching Id?

Show the values of $bank_list and $redemptions_prod variables.

Dec
28
1 month ago
Activity icon

Replied to How To Validate Image In Edit Form If There Is No Image Is Selected

I would rather suggest you to create two request classes. ProductCreateRequest and ProductUpdateRequest

ProductCreateRequest.php

public function rules()
    {
        return [
            'name' => [ 'required' ],
            'image' => [ 'required','image','mimes:jpg,png,jpeg' ],
        ];
    }

ProductUpdateRequest

Here, you simply put the image rule as nulllable. So image will only be validated if it exists

public function rules()
    {
        return [
            'name' => [ 'required' ],
            'image' => [ 'nullable','image','mimes:jpg,png,jpeg' ],
        ];
    }
Dec
27
1 month ago
Activity icon

Replied to Compact(): Undefined Variable

The issue could be with php versions as well. I degraded my php version from 7.4 to 7.1 and it got resolved !

Activity icon

Replied to How To Divide Bootstrap Card Class To Same Size 3 Horizontal Boxes And 2 Vertical Boxes For Image Gallery

Umm... simply use grids?

<div class="row">
    <div class="col-md-4"></div>
    <div class="col-md-4"></div>
    <div class="col-md-4"></div>

    <div class="col-md-6"></div>
    <div class="col-md-6"></div>
</div>

You may run into image height problem. You can resolve it by the followings

  • One option is to have appropriate size of images so that you do not have to manage the image size in HTML and CSS
  • Set height manually through css
  • You can do something like this to have your images more responsive as well.
<div class="row gallery">
    <div class="img col-md-4" style="heigh:300px; background-image: url(...)"></div>
    <div class="img col-md-4" style="heigh:300px; background-image: url(...)"></div>
    <div class="img col-md-4" style="heigh:300px; background-image: url(...)"></div>

    <div class="img col-md-6" style="heigh:600px; background-image: url(...)"></div>
    <div class="img col-md-6" style="heigh:600px; background-image: url(...)"></div>
</div>

.gallery img{
    width: 100%;
    backgrouund-size: cover;
    background-position: center;
}
Dec
16
2 months ago
Activity icon

Started a new Conversation Best Practices To Debug In Production

I am having some hard time debugging api and project in production. My laravel version is old (5.4), so i cannot use debugbar as well.

In local we can quickly dd() variables and see whats going on.

But in production, I feel stuck. Everytime i have to do some changes, push, deploy and test. This is very tedious.

Can anyone experienced suggest good practices/packages ?

Dec
11
2 months ago
Activity icon

Started a new Conversation Dynamic Request Class Injection In Laravel

I have a custom request class which is getting longer and longer with project development.

An API endpoint is expected to have multiple types ofinput. Any one is expected to be received at once.

According to the input, the validation rules are being constructed.

Right now I am having a long list of swith-cases to construct validation rules.

I want to create multiple requests classes for each case and dynamically inject appropriate request class to the controller method. Note that I cannot create multiple api endpoints.

Is there any good suggestion to handle this?

Dec
10
2 months ago
Activity icon

Replied to Property [Musd] Does Not Exist On This Collection Instance.

unable to understand your question mate

Activity icon

Replied to Symfony Process: Command Not Found

Tried but no luck.

It returns the appropriate paths.

[edit]

Error Output:
================
env: node: No such file or directory
Activity icon

Replied to Symfony Process: Command Not Found

yes. Everything works fine with standalone terminal

Activity icon

Replied to Symfony Process: Command Not Found

@nakov basically want to execute shell command from php.

It worked just fine using shell_exec, but the user input is expected to have any valid UTF-8 character, so its not possible to sanitise the input i guess.

So my best chance is to use something like Process.

I would appreciate if you can suggest any alternatives as well.

Thanks

Activity icon

Replied to Symfony Process: Command Not Found

Hey, thanks for reply @nakov

the user on your application server might be different than the default from your terminal

I executed whoami from Process() and terminal. Both returns same username only.

And trying to run any other util that is part of your /usr/local/bin?

I ran two commands from /usr/local/bin

Process(['npm','v']); //command not found
Process(['httpd','v']); // worked

How do I debug this, I don't understand.

One of my friend @sinnbeck tested the same thing on linux i guess, it worked just fine. Could it be an OS issue?

Activity icon

Started a new Conversation Symfony Process: Command Not Found

I am using Symfony Process component.

I have installed this.

resolution command works just fine in my terminal. However I am not able to use it with Process()

CODE

$process = new Process('resolution');
$process->run();

OUTPUT

The command "resolution" failed.
Exit Code: 127(Command not found)

I tried to echo the$PATH variable.

CODE

$process = new Process('echo $PATH');

OUTPUT

/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.

The resolution command is stored in /usr/local/bin , so it should work i believe.

All the solutions on the internet points towards checking the $PATH which does not seem like an issue.

Even if I write entire path of the command, it wont work with Process component. It works in normal terminal just fine

CODE

$process = new Process('/usr/local/bin/resolution');
$process->run();

OUTPUT

The command "resolution" failed.
Exit Code: 127(Command not found)

I have tested my code with different laravel versions as well (5.4 and 8). Facing the same issue

Dec
09
2 months ago
Activity icon

Replied to Gitignore Advise For Laravel Please

I believe the .gitignore files ships with laravel project template by deafaut. Why do you need to configure it like this by yourself?

Activity icon

Started a new Conversation Best Way To Read Config File Within A Service Provider

I have a custom package like this in my project

App
    Services
      MyPackage
        Exceptions
        config
            config_to_be_published.php
            config_for_internal_use.php
        Facades
        ServiceProvider.php
        Service.php

Here, what is the best way to access config_for_internal_use.php within Service.php ?

Usually in laravel we would use config() to read the configs.

How should I go about this?

Dec
08
2 months ago
Activity icon

Replied to Throttling: Different Rate Limit For Different Users.

I will take a look into it. And that laravel episode was helpful. Thanks !

Activity icon

Replied to Throttling: Different Rate Limit For Different Users.

ahh.. its an old version :P

5.4

Activity icon

Started a new Conversation Throttling: Different Rate Limit For Different Users.

Framework version: 5.4

I want to set different rate limits for different types of users. Any tips?

I assume there is no dedicated way to do it.

Dec
07
2 months ago
Activity icon

Started a new Conversation How To Sanitise User Inputs For `shell_exec()`

  • I am working on a node module that runs on CLI
  • I am executing shell a command from php to interact with the node module
  • I am taking 2 inputs from user and passing it to one shell command
shel_exec("command -flag1 $data1 -flag2 $data2;")
  • How do I sanitise $data1 and $data2 properly?
  • The inputs are expected to have only these symbols .,- and _

I am bound to go with this approach only, so I want to minimise the risk as much as possible.

Can anyone good with linux help me out here?

Nov
25
3 months ago
Activity icon

Replied to Base Table Or View Does Not Exist

Revisit the question mate. @munazzil

Activity icon

Replied to Base Table Or View Does Not Exist

Well yeah I did that only and it worked. But I put put out this question to understand why it happened.

Activity icon

Replied to Base Table Or View Does Not Exist

As I have mentioned, the issue is it is trying to access oldBD.table, but I do not have that db in my server. I have my target database with other name and it has everything that is needed. I am trying to clear the cache so that the app can connect to the database of which credentials I have added in the env. @tray2

Activity icon

Replied to Base Table Or View Does Not Exist

well the problem with the migrations is that they are not maintained by the original developers. So the database is cloned directly from server to localhost @marianomoreyra

Nov
24
3 months ago
Activity icon

Started a new Conversation Base Table Or View Does Not Exist

  • I cloned a project from github
  • I changed the database credentials from remote to local in .env
  • Everything works fine.
  • But then I changed the env variables again and try to config cache but got this error
Base table of view does not exist...

I tried to run the following commands

php artisan cache:clear
php artisan config:cache

But still instead of rewriting the cache, artisan was throwing the same error. It is trying to make db request by using old env variables. How do I fix this?

Nov
23
3 months ago
Activity icon

Replied to Laravel Accessors On Query Builder

Well, I don't think you are sending 500 records in one api request, are you? You should paginate your eloquent queries like this.

docs

https://laravel.com/docs/8.x/pagination

Activity icon

Replied to Limit The Number Of Records Created Per Day In A Model

That is not an efficient solution here.

Imagine that a user tries to create the post but it fails because of some validation error. Now user will correct the error and send a 2nd request to create a post and this time the post will be stored. So user actually accessed the route 2 times but only 1 post was created.

So the number of route visits cannot not represent the number of post creations.

Activity icon

Replied to Limit The Number Of Records Created Per Day In A Model

  • You can save the max number of posts in a configuration file.
  • Or you can create a middleware that will check the number of posts created and only allow access to the route if the limit is not exceeded
Activity icon

Replied to Limit The Number Of Records Created Per Day In A Model

@astersnake

Well that's simple

$numberOfPosts = Post::whereDate('created_at', Carbon::today())->count();
if($numberOfPosts < 50){
	// create post
}
Activity icon

Replied to Should The Logout Route Be Protected Or Not

try this

Auth::guard('web')->logout();
Activity icon

Replied to My Registration Process Is So Slow [ 5 : 9 Seconds ]

Can you give some more information? Show the controller code for registration

Nov
21
3 months ago
Activity icon

Replied to Foreign Keys

Short answer, No. Unless you have a very good reason to do it or your primary key in the reference table is represented by a string.

Nov
20
3 months ago
Activity icon

Awarded Best Reply on A Good Way To Notify Users Through Email Of Some Event?

Its very simple. Learn these two things to implement it in laravel

  • Events and listeners
  • Sending mails

Video explination

https://www.youtube.com/watch?v=6wZKwJQF7Is

Docs

https://laravel.com/docs/8.x/events

https://laravel.com/docs/8.x/mail

Activity icon

Replied to A Good Way To Notify Users Through Email Of Some Event?

Its very simple. Learn these two things to implement it in laravel

  • Events and listeners
  • Sending mails

Video explination

https://www.youtube.com/watch?v=6wZKwJQF7Is

Docs

https://laravel.com/docs/8.x/events

https://laravel.com/docs/8.x/mail

Activity icon

Replied to How To Create A Dynamic Labels In Month In Chart Js

@gitwithravish can you please put your code between triple quotes so that i can read?

Nov
18
3 months ago
Activity icon

Replied to True Or False Statements

@tomasosho Happy to help :)

Activity icon

Awarded Best Reply on True Or False Statements

So try to understand whats the problem here. You are trying to search a value in an array of collections. It doesn't work like the way you have implemented.

Rather this might work for you.

$result = auth()->user()->following()->where('user_id',$user->id)->first();
if($result){
	$follows = true;
}else{
	$follows = false;
}
Activity icon

Replied to True Or False Statements

do you have a many to many pivot table or not?