chaudigv

Member Since 1 Month Ago

Experience Points
4,560
Total
Experience

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
16
Lessons
Completed
Best Reply Awards
3
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 1
4,560 XP
Jan
17
19 hours ago
Activity icon

Replied to LARAVEL Array Get Issue

I want to get null or empty string if the value is null

Please explain.

Activity icon

Replied to Add Rate Limit To A Livewire Component

Hey @danharrin, I am facing an issue while installing. I have created a discussion on github. Could you please take out some time and assist me on this. Thanks.

Activity icon

Replied to Uncaught ReferenceError: Livewire Is Not Defined

In your .env file, verify the APP_URL.

APP_URL=http://127.0.0.1:8000 // match this and try again

Activity icon

Replied to Uncaught ReferenceError: Livewire Is Not Defined

Did you ran php artisan livewire:publish --assets to publish frontend assets?

Jan
16
1 day ago
Activity icon

Replied to Convert Recursive Array To Single Array

A simple recursive loop can help you in such situations.

// If $recursive exists and have inner another array
while ($recursive && $recursive['another']) {
    $single[] = [
        'id' => $recursive['id'],
        'name' => $recursive['name']
    ];
    $recursive = $recursive['another'];
}

// Get the last outer another array
$single[] = [
    'id' => $recursive['id'],
    'name' => $recursive['name']
];

dd($single); // this will return your expected format
Activity icon

Replied to Trying To Get Property 'tags' Of Non-object When Edit Data

Some of your Post model does not have tags. In such case it's always better to have a default value when a property does not exists. Simply add ??

{{ $data->tag->tags ?? 'No Tags' }}
Activity icon

Replied to How To Manually Delete User In Jetstream

I suggest to ask for password when a user chooses to login via social. Simple straight forward.

or

Create a middleware that checks for password, if it doesn't exists, force them to set a password and then continue.

Activity icon

Replied to Auto Logout After Submit Form Laravel

in controller status is change and in response success

// change status

return redirect('login')->with(Auth::logout());
Jan
15
2 days ago
Activity icon

Awarded Best Reply on Livewire 'disabled Selected' On Select Field

Whatever value $lunch holds, respective value will be selected.

I suggest to keep the value empty

$lunch = '';

// no mount function needed

and

<option value="" disabled>Choose One</option> // no need to use selected attr

I guess, this is still same way of doing what you did.

Activity icon

Started a new Conversation Add Rate Limit To A Livewire Component

I have a newsletter livewire component which accepts an email and do create/read operation.

I would like to add a rate limit to this component. That is, allow users to submit the newsletter form 10 times per minute.

I am able to achieve this by setting 'middleware_group' => ['web', 'throttle:10,1'], in config/livewire.php. But this will apply to every livewire calls. I do not want that.

And since this is not directly called from a route, in such case I would have simply added rate limit from the web.php itself, I'm not sure how to add to a livewire component only.

Activity icon

Replied to LiveWire Https Issue

To keep the assets up-to-date and avoid issues in future updates, it is highly recommend adding the command to the post-autoload-dump scripts in your composer.json file:

{
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi",
            "@php artisan vendor:publish --force --tag=livewire:assets --ansi" // this
        ]
    }
}
Activity icon

Replied to Livewire 'disabled Selected' On Select Field

Whatever value $lunch holds, respective value will be selected.

I suggest to keep the value empty

$lunch = '';

// no mount function needed

and

<option value="" disabled>Choose One</option> // no need to use selected attr

I guess, this is still same way of doing what you did.

Jan
13
4 days ago
Activity icon

Replied to Laravel Cache

Simply use the logged in user's id while naming the cache.

Cache::remember('articles_' . Auth::user()->id, ...

This way each user will have their own cached articles based on the id.

Jan
12
5 days ago
Activity icon

Replied to Is It Possible To See Raw Sql Query?

use Illuminate\Support\Facades\DB;

DB::enableQuery();
Bill::with(['user', 'project'])->get();
dd(DB::getQueryLog()); // list of all the queries

Jan
11
6 days ago
Activity icon

Replied to Disable Submit Button Livewire Validation

Simply add this to your submit button wire:loading.attr="disabled". You don't need additional boolean variable to do so.

Check livewire loading states for more info.

Activity icon

Replied to Livewire Search Component.

You can use findOrFail()

use Illuminate\Database\Eloquent\ModelNotFoundException;

public $error = '';

try {
    $this->product = Product::findOrFail($this->search);
    $this->reset(['error']); // set $error to default i.e. ''
} catch(ModelNotFoundException $e) {
    $this->error = 'Product not found.'; // your message when not product found.
}

In your blade

@if(!empty($error))
    {{ $error }}
@endif
Jan
10
1 week ago
Activity icon

Replied to Call To Undefined Method Illuminate\Database\Query\Builder::replicating()

It's hard to pin point why you are facing such error because that is a huge jump forward. Instead of upgrading 5.3 directly to 7, I would highly recomend to upgrade your current project by each version.

Go to 5.4 upgrade guide. And follow through each version's upgrade guide.

A while ago, I wrote an answer on stack overflow Upgrading Laravel 5.0 to the latest version (7.x). This will give you a good head start.

Activity icon

Replied to Livewire Mount Fields

Shouldn't the $extras be an array?

$this->extras[] = [$xs[$i]->extra_id => $xs[$i]->extra_value];
Activity icon

Replied to Laravel Livewire File Type Image Not Nullable

Please share relevant code.

Jan
09
1 week ago
Activity icon

Replied to Laravel Encrpt/Decrypt With Custom Key?

I found a similar thread https://laracasts.com/discuss/channels/laravel/encrypt-with-specific-key

Even though it's old, still a quick jump start is better than no info.

Activity icon

Replied to How Can I Dynamically Add WHERE Clauses In Eloquent?

Let's say you have checkboxes setup for this:

<input name="buildingDesc[]" type="checkbox" value="single_family" />

<input name="buildingDesc[]" type="checkbox" value="condo" />

In your controller:

->where(function ($query) {
    $query->when(in_array('single_family', request('buildingDesc')), function ($q) {
        $q->orWhere('BuildingDesc', 'Single Family');
    })
    ->when(in_array('condo', request('buildingDesc')), function ($q) {
        $q->orWhere('BuildingDesc', 'Condo');
    });
})
Activity icon

Replied to CSRF Token Mismatch.

Confirm the settings, this is what I have been using.

under your bootstrap.js file.

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Next we will register the CSRF Token as a common header with Axios so that
 * all outgoing HTTP requests automatically have it attached. This is just
 * a simple convenience so we don't have to attach every token manually.
 */

let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

And app.js will load the bootstrap file.

And in your main blade layout file (probably app.blade.php)

<meta name="csrf-token" content="{{ csrf_token() }}">

<script src="{{ mix('js/app.js') }}"></script>
Activity icon

Awarded Best Reply on Question About LIvewire Validation Ignore.

You need to use rules() as a method instead of property

use Illuminate\Validation\Rule;


public function rules()
{
    return [
        'title' => ['required', Rule::unique('blogs')->ignore($this->title)],
        'content' => 'required|min:10'
    ];
}
Jan
08
1 week ago
Activity icon

Replied to Security Concern About Livewire Render Method

@vguerrero Why don't you change the order

$this->project = $project;
$this->authorize('view', $this->project);
Activity icon

Replied to Tiny MCE Is Sending Request To Server For Each Key

Try if wire:ignore can help you in this situation. Here's the doc https://laravel-livewire.com/docs/2.x/alpine-js on how to implement it.

Jan
07
1 week ago
Activity icon

Replied to Example Of Livewire Based Select To Filter Results

@ssmusoke You can get a head start with this YouTube tutorial Laravel Movie App - Search Dropdown w/ Livewire

Eventually, you can post some code for us to work with.

Activity icon

Replied to Create:893 Livewire: The Published Livewire Assets Are Out Of Date See: Https://laravel-livewire.com/docs/installation/

Just for reference, livewire docs have specifically mentioned this. https://laravel-livewire.com/docs/2.x/installation

To keep the assets up-to-date and avoid issues in future updates, we highly recommend adding the command to the post-autoload-dump scripts in your composer.json file:

{
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi",
            "@php artisan vendor:publish --force --tag=livewire:assets --ansi"
        ]
    }
}
Activity icon

Replied to Question About LIvewire Validation Ignore.

You need to use rules() as a method instead of property

use Illuminate\Validation\Rule;


public function rules()
{
    return [
        'title' => ['required', Rule::unique('blogs')->ignore($this->title)],
        'content' => 'required|min:10'
    ];
}
Jan
03
2 weeks ago
Activity icon

Replied to Livewire Update Not Working Even With Key

@yoman I came across exact issue multiple times... I simply append time() to the key.

  <livewire:user.show :user="$user" :key="$user->id . time()">
Activity icon

Replied to How To Pass An Array From Controller To Livewire

Give this a try

return redirect()->route('jobSearchResult', ['jobs' => $jobs]); // keep this as Eloquent\Collection and not an array

In your livewire component,

public $jobs = null;

public function mount($jobs) {
    $this->jobs = $jobs;
}

Follow this docs for more info

https://laravel-livewire.com/docs/2.x/rendering-components

https://laravel.com/docs/8.x/redirects#redirecting-named-routes

Activity icon

Replied to Livewire Event Listeners Failing To Re-render Or Manipulate The DOM

Always a good practise to add a :key when rendering a component.

<livewire:front.post.like-post :key="$post->id" :post="$post" :liked="$post->likedBy(auth()->user())"/>

Jan
02
2 weeks ago
Activity icon

Replied to Expired Session Not Redirect To Login [Laravel Jestream]

I have not yet come across such an issue. Try adding the refresh meta tag.

<meta http-equiv="refresh" content="{{ config('session.lifetime') * 60 }}">

For logged in users, after the session lifetime the page will refresh and they will be returned to the same page, however they will no longer be authorised so will be redirected however the auth middleware is configured.

For more info, check https://talltips.novate.co.uk/laravel/csrf-and-expired-login-forms

Activity icon

Replied to LiveWire: How To Action The Value Of An Input Without A Button

You can simply use wire:change="save()" on the input tag.

Activity icon

Replied to Override Created_at

::create() will automatically add created_at and updated_at values upon creation.

Rather use ::insert()

if($request->filled('backdate')) {
    $date = request('backdate');
} else {
    $date = Carbon::now()->format('Y-m-d H:i:s');
}

$data = [
    'created_at' => $date
];

Sales::insert($data);
Activity icon

Replied to Eloquent OrderBy Based On Two Fields

Also, you can specify the order type

$users = DB::table('users')
                ->orderBy('name', 'desc')
                ->orderBy('email', 'asc')
                ->get();

For more details, please check out the docs https://laravel.com/docs/8.x/queries#orderby

Activity icon

Replied to Laravel Schedule

I suggest trying with proper dateTime() format

Carbon::now()->format('Y-m-d H:i:s')

Activity icon

Replied to Modal Close On Start Typing Inside Any Input How To Fix It Using Livewire

@respect Your question is unclear. Please specify the issue, what to expect and only relevant code.

Activity icon

Replied to Trying To Get Property 'courses' Of Non-object

Since ->first(); returns null. It's better to validate conditions before accessing any relations.

e.g. if($cart && $cart->courses)

Activity icon

Awarded Best Reply on Tailwind Overflow

You need to add whitespace-pre class for controlling an element's white-space property. https://tailwindcss.com/docs/whitespace

Activity icon

Replied to Tailwind Overflow

You need to add whitespace-pre class for controlling an element's white-space property. https://tailwindcss.com/docs/whitespace

Dec
25
3 weeks ago
Activity icon

Replied to Livewire S3 File Upload Unit Test

Link inside my description is same as what you have provided. And I am using the same code/standard suggested in the article.

Activity icon

Started a new Conversation Livewire S3 File Upload Unit Test

I am following Testing simple S3 uploads but facing a simple issue on assertExists()

Current versions: Laravel 8.20.1 Livewire: 2.3.5 phpunit: 9.3.3

Code

    public function test_resume_file_is_uploaded_successfully()
    {
        $this->actingAs(User::factory()->create());

        Storage::fake('s3');

        $file = UploadedFile::fake()->create('resume.pdf');

        Livewire::test(Upload::class)
            ->set('resume', $file)
            ->call('uploadResume')
            ->assertHasNoErrors();

        $this->assertTrue($user->refresh()->resume()->exists());

        Storage::disk('s3')->assertExists(config('app.asset_url') . '/' . $user->refresh()->resume->file_name); // --> this is where I am facing error
    }

Error

  • Tests\Feature\ResumeTest > resume file is uploaded successfully
  Unable to find a file at path [https://***.cloudfront.net/resume/ZSe4ePnkW8CqilXnXZCb6O0tTJKcWAn00i5J61E9.pdf].
  Failed asserting that false is true.

Code works since I can upload and verify the file on s3 when I test from browser. Just need little guidance when doing same via unit test.

Appreciate your help.

Activity icon

Replied to Livewire Mask Input

Could you please elaborate more on this.

@bestmomo replied to a similar thread 6 years ago. Maybe now he can add more info to it if there's been any improvement. See https://laracasts.com/discuss/channels/general-discussion/laravel-inputs-with-masks

Dec
24
3 weeks ago
Activity icon

Replied to Skip Accessors/mutators While Unit Testing With Make() Instead Of Create()

You are right. I should simply create a new stylized accessor for the blade views and use the default (raw value from database) to play around with the unit tests.

Activity icon

Replied to Skip Accessors/mutators While Unit Testing With Make() Instead Of Create()

I need the overwritten (stylized) value for blade files and the raw value for mailing. Everything works well when I use create() for unit tests but that creation defeats the purpose of testing it. I just need a workaround for the make() method.

Activity icon

Replied to Skip Accessors/mutators While Unit Testing With Make() Instead Of Create()

Still returns the value based on the accessor conditions.

Activity icon

Replied to Skip Accessors/mutators While Unit Testing With Make() Instead Of Create()

I have few columns that are stylized based on multiple conditions set under accessor/mutator functions. In some scenarios I still need access to the original value like sending the value in an email. Hence the need.

Activity icon

Started a new Conversation Skip Accessors/mutators While Unit Testing With Make() Instead Of Create()

Case 1: using create()

$user = User::factory()->create(); // this will create and save the user in the database (https://laravel.com/docs/8.x/database-testing#persisting-models)

$user->getRawOriginal('status') will skip the mutator and returns exactly what's in the database.

Case 2: using make()

$user = User::factory()->make();// make method to create models without persisting them to the database (https://laravel.com/docs/8.x/database-testing#instantiating-models)

$user->getRawOriginal('status') // returns null

$user->status // gives mutated value

I want to use the the raw value using make() for unit testing purpose. How to achieve that?

Dec
17
1 month ago
Activity icon

Replied to Combine Livewire Component With Alpine

With the new verson of livewire (2.x), you can use $wire and @entangle to communicate with alpine to/from livewire.

Please check the docs https://laravel-livewire.com/docs/2.x/alpine-js

Also, please add some code if you would like to continue discussing this thread. Thanks.

Activity icon

Replied to Livewire Initialize With Args

Two ways of passing parameters:

<livewire:fav-user :target_user_id="$user->id">

@livewire('fav-user', ['target_user_id' => $user->id])

Please check docs https://laravel-livewire.com/docs/2.x/rendering-components