mkshingrakhiya

mkshingrakhiya

Member Since 4 Months Ago

Porbandar

Experience Points
10,560
Total
Experience

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

Level 3
10,560 XP
May
29
15 hours ago
Activity icon

Awarded Best Reply on Select All Records With At Least 1 Related Record

You can use has() to get records with at least one defined relationship record.

$specialities = Speciality::has('groups')
    ->with('institute', 'groups')
    ->where('institute_id', '=', $id)
    ->orderBy('name', 'ASC')
    ->get();
Activity icon

Replied to Select All Records With At Least 1 Related Record

You can use has() to get records with at least one defined relationship record.

$specialities = Speciality::has('groups')
    ->with('institute', 'groups')
    ->where('institute_id', '=', $id)
    ->orderBy('name', 'ASC')
    ->get();
Activity icon

Replied to Json Response To Blade

public function test(Request $request)
{
    $today = date('Y-m-d'); // This is how you get current date
    $widgetId = $request->query('widgetId'); // This is how you get params from query
}
Activity icon

Replied to Json Response To Blade

Store it in variables like $period = '2020-05-29 - 2020-05-29; and then Arr::get($data, "{$period}.86xx3.revenue")

You could also store 86xx3 into a variable and replace literal with that variable.

Activity icon

Replied to Json Response To Blade

If you're passing JSON string, then you need to convert it back to an array. Then use {{ $data['2020-05-29 - 2020-05-29']['86xx3']['revenue'] }}

Activity icon

Replied to Json Response To Blade

return view('dashboard', [
    'data' => json_encode($data)
]);

But why do you want to pass JSON into views?

You could also pass it normally as you did in your question and then in your view, use @json($data) to convert to JSON string.

May
28
1 day ago
Activity icon

Replied to PHP Variable Mutation

It should not be doing that. You might have other issues there.

Activity icon

Replied to Accessor On Some Pages

Use accessor only when you need to. It is not necessary to define an accessory with field names only. You can name it whatever you want.

public function getShortStringFieldAttribute()
{
   return substr($this->string_field, 0, 100);
}
Activity icon

Replied to Events On Pivot

Well, I'm directly updating the pivot table so any other way would be great.

Activity icon

Replied to PHP Variable Mutation

It is maybe because you've provided additional conditions in second statement. Try dd($loans->count()); after the second statement and it might still return the original count.

Activity icon

Replied to Run Job Every Second Laravel

Why not? Create a command and inside fire the queued job.

Activity icon

Replied to Need Help With Select Statement

I presumed sponsorapp is the relationship you already defined in User model.

User::with(['sponsorapp:id'])
    ->whereHas('roles', function ($query) {
        $query->where('name', 'sponsor');
    })
    ->get(['username']);
Activity icon

Started a new Conversation Events On Pivot

How to track changes in Pivot model? Already tried closures and observers but it's not working.

Activity icon

Replied to Run Job Every Second Laravel

Another way would be with the use of shell script. The below code would fire the command and then sleep for a second. It will run in infinite loop and as @snapey already mentioned, you could also configure supervisor to start this script when the system boots.

#!/bin/bash

while true; do
  # /path/to/php /path/to/artisan command
  sleep 1;
done
Activity icon

Replied to Run Job Every Second Laravel

Change the statement like below. It will automatically execute it every second.

public function schedule(Schedule $schedule)
{
    CheckBotDelay::dispatch();
}
Activity icon

Replied to App()->getLocale() Is Always Default Locale

See the ordering of registered middlewares. Did you define it at the end?

May
27
2 days ago
Activity icon

Replied to Access MorphedByMany

I still don't see any potential errors in this code. Make sure you have proper database tables. However, App\Taggable is not required and your controller has multiple return statements. Try to follow or compare your code with the Laravel Docs.

Activity icon

Replied to How To Send Data To Pusher

You're welcome!

Activity icon

Awarded Best Reply on How To Send Data To Pusher

As I told you, through the dispatch().

PaymentStatusUpdate::dispatch($params);

Then access it in the constructor of PaymentStatusUpdate.

Activity icon

Replied to Access MorphedByMany

Could you share your controller and model here? I don't see any error in the provided code and check if $tag is an instance of Tag model first.

Activity icon

Replied to Delete Unused File

You're passing $filepath and $filename separately. You should pass $filepath . $filename as a single argument.

Storage::delete('public/avatars/' . $userFolder . '/' . $fileName);

And make sure the file exists.

Activity icon

Replied to Delete Unused File

Storage::delete() expects a full filepath.

Activity icon

Replied to How To Send Data To Pusher

As I told you, through the dispatch().

PaymentStatusUpdate::dispatch($params);

Then access it in the constructor of PaymentStatusUpdate.

Activity icon

Replied to Access MorphedByMany

Make sure your Tag model extends Illuminate\Database\Eloquent\Model.

Activity icon

Replied to How To Send Data To Pusher

Pass data through the dispatch method and then either store the data in public property or define a method broadcastWith and return an array.

See Broadcast Data

Activity icon

Replied to Laravel Doesn't Order Collection By Expected Order

@michaloravec Yeah! I agree. I mean it is a pretty basic concept.

Activity icon

Replied to Laravel Doesn't Order Collection By Expected Order

@michaloravec I am retrieving it from the database, am I not? @ehsanm I have tested the code I've suggested and it works.

Activity icon

Replied to Laravel - Getting Empty JSON On User Model In Controller

It should be inside FollowController and you have insufficient code in there. See below.

public function store(User $user)
{
    auth()->user()->follows()->toggle($user->id);

    return back();
}
Activity icon

Replied to Laravel Doesn't Order Collection By Expected Order

Ordering on VARCHAR fields is done by ASCII values and that is why you're getting what you're getting. Try the below code and see if it works.

App\Post::orderByRaw("CAST(views AS UNSIGNED) DESC")->pluck('views');

It is not tested but it should work.

Activity icon

Replied to Which Is Better For Using API ?

I recommend API resources. They are flexible and can help you reduce duplicate code. They also let you manage the data transformation easily and in one place.

May
26
3 days ago
Activity icon

Commented on Build The Follow Form

I used invokable ToggleFollowController to handle the toggling. I think it is neat.

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\RedirectResponse;

class ToggleFollowController extends Controller
{
    /**
     * Toggle the following of the user.
     *
     * @param  User  $user
     * @return RedirectResponse
     */
    public function __invoke(User $user): RedirectResponse
    {
        auth()->user()->follows()->toggle($user->id);

        return back();
    }
}

Activity icon

Replied to Elequent GroupBy Date And Order By Asc Inside The Date Group

I'm confused. Do scan images have a separate table or it is a single table and you're trying to first group the records and then sort records in each group by order field?

Activity icon

Replied to Elequent GroupBy Date And Order By Asc Inside The Date Group

Hey @skoobi, Could you please try...

$collection = CustomerScan::where('user_id', $user->id)
    ->orderBy('order_field', 'order_direction')
    ->get()
    ->groupBy(function ($item) {
        return $item->created_at->format('Y-m-d');
    });
May
25
4 days ago
Activity icon

Commented on Expanding The Timeline

@fullwebservice @jhargett @zabeh You could do it like...

/**
 * Get all the followers of this user.
 *
 * @return BelongsToMany
 */
public function followers(): BelongsToMany
{
    return $this->belongsToMany(User::class, 'follows', 'following_user_id', 'user_id');
}

/**
 * Get the timeline of this user.
 *
 * @return Collection
 */
public function timeline(): Collection
{
    return Tweet::where('user_id', $this->id)
        ->orWhereHas('user', function ($query) {
            $query->whereHas('followers', function ($query) {
                $query->where('user_id', $this->id);
            });
        })
        ->latest()
        ->get();
}
Activity icon

Awarded Best Reply on Shift Active Filter To Model For Record And Relationship

You should move the code into trait and use that trait wherever required.

Activity icon

Replied to Shift Active Filter To Model For Record And Relationship

You should move the code into trait and use that trait wherever required.

Activity icon

Replied to Shift Active Filter To Model For Record And Relationship

It is in the product model and you're using the query scope on both models.

Activity icon

Replied to Shift Active Filter To Model For Record And Relationship

Did you also define query scope in user model?

Activity icon

Replied to BelongsTo Relation Gets Null Output.

@princeoo7 Then load the relation and return it like in the example. It doesn't have to be complicated.

Activity icon

Replied to BelongsTo Relation Gets Null Output.

@princeoo7 You could use it the way @nakov said for API also. Just load the relationship before sending JSON response.

$product->load('brand');

return response()->json(compact('product'))

or if you're using API resources

public function toArray($request)
{
    return [
        'brand' => new \App\Http\Resources\Brand($this->whenLoaded('brand')),
    ];
}

I suggest you use API resources if you're not already using it.

May
23
6 days ago
Activity icon

Replied to Saving Values With ->resolveUsing And ->displayUsing

You can use one of the above methods to do what you want. You just need to specify it on the model with whatever field you want.

Activity icon

Replied to Query Builder Returning Null

Hey there, could you please mark it as a "Best Answer". It helps everyone finding similar solutions and will also help me.

Activity icon

Replied to Data Truncated - $faker->randomElements

If you want to store multiple values into the field then ENUM won't work. You need a field that can store strings without restrictions such as VARCHAR, TEXT, SMALLTEXT, etc depending on the size requirement of your field.

Then, in your model cast interest_tags attribute/field to an array.

protected $casts = [
    'interest_tags' => 'array'
];

Now you can store arrays to this field by just assigning it to the field like you already mentioned in your question.

'interest_tags' => $faker->randomElements(['php', 'javascript', 'vue'], 2),
May
22
1 week ago
Activity icon

Replied to How To Link Up Storage Files

Did you set the correct permissions to the storage directory? Visit this StackOverflow thread to assign proper permissions to the storage directory and then give it one more try. Also, see what happens when you call Storage::exists("images/{$slide-slide}").

Activity icon

Replied to Laravel Mix - If At All / Using It To What Extent?

Yes. It is better than serving too many smaller assets. However, To further improve the assets serving in your Laravel application, see Vendor Extraction part of the Laravel Mix.

Activity icon

Replied to Data Truncated - $faker->randomElements

You should use VARCHAR instead of ENUM as VARCHAR is more flexible than ENUM and then validate value before storing it to the database. However, if you still want to use ENUM then the below code should fix the error you're getting.

'interest_tags' => $faker->randomElement(['php', 'javascript', 'vue']);
Activity icon

Replied to Searching Select List In Laravel 7

Check out Laravel Livewire. It might help you to build what you need.

Activity icon

Replied to How To Link Up Storage Files

This should work

public function download(Slide $slide)
{
    return Storage::download("images/{$slide-slide}");
}

PS: Prefix Storage with \ or import Storage facade.

May
21
1 week ago
Activity icon

Awarded Best Reply on 404 Error On Form Update

Hey @anibabbar, You should remove $ from route declaration.