MarianoMoreyra

MarianoMoreyra

Member Since 4 Months Ago

Buenos Aires

Experience Points
85,750
Total
Experience

4,250 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
239
Lessons
Completed
Best Reply Awards
100
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 18
85,750 XP
Nov
28
1 day ago
Activity icon

Replied to Livewire Date Validation For E.g. Before_or_equal:

Glad it worked @chaudigv !!

Actually, Livewire uses Laravel validation rules, and this is case is documented here:

https://laravel.com/docs/8.x/validation#rule-after

Activity icon

Awarded Best Reply on Livewire Date Validation For E.g. Before_or_equal:

Hi @chaudigv

Try with this:

protected $rules = [
	'start_date' => ['required', 'before_or_equal:today'],
]

Hope this works for you!

Activity icon

Replied to Livewire Date Validation For E.g. Before_or_equal:

Hi @chaudigv

Try with this:

protected $rules = [
	'start_date' => ['required', 'before_or_equal:today'],
]

Hope this works for you!

Activity icon

Replied to Create A Sidebar Menu With Fontawesome Icon And Menu Name

Hi @silverground

It's not clear to me what is the part you don't know how to do.

  • You don't know how to make a sidebar accesible to all your pages?
  • Don't know how to fetch data from a database within your Controller and render it on a page?
  • Don't know how to dynamically render the menu based on the text and link fetched from database?

In any case, if you don't know any of those questions, or all three of them, you may want to take a look at Laravel from Scratch course:

https://laracasts.com/series/laravel-6-from-scratch

If you know the basics but don't know how to create a layout to render the same sidebar in any page, maybe you can skip to the "Layout Pages" episode:

https://laracasts.com/series/laravel-6-from-scratch/episodes/14

Hope this helps!

Nov
27
2 days ago
Activity icon

Replied to Livewire Binded Check Boxe's Checked Attribute Is Not Working

I'm glad it worked @mathewp

Another one-line alternative for syncing:

$user->permissions()->sync(array_keys(array_filter($this->selections)));
Activity icon

Awarded Best Reply on Livewire Binded Check Boxe's Checked Attribute Is Not Working

Hi @mathewp

You can't use checked with livewire. You have to bind the inputs to an array (as you seem to be doing) and then on mount() method, populate that array with the options you fetch from database:

Maybe there is some easier way, but this is how I managed to make it work:

public function mount()
{
    $this->selections = array_fill_keys(User::with('permissions')
          ->find(1)  // just for testing purposes I'm hardcoding the ID to fetch
          ->permissions
          ->pluck('id')
          ->toArray(), 
        true);
}

Then at your view you have to use the dot notation to bind to an array, using the $perm->id as an index:

@foreach ($permissions as $perm)
    <div class="mt-1">
        <label class="inline-flex items-center">
        <input  wire:model="selections.{{$perm->id}}" type="checkbox"   
            class="w-6 h-6 text-green-500 form-checkbox "
         >
         <span class="ml-3 text-sm">{{ $perm->name }}</span> </input>
         </label> 
    </div>
@endforeach

You have to consider that if you check an option, and then un-check it again, you will have a false a the corresponding ID.

So before saving to database, you should filter the array to only keep those with a true value. Also, consider that the ID to persist to database, will be the key of the array instead of the value.

Hope this works for you!

Activity icon

Replied to Livewire Binded Check Boxe's Checked Attribute Is Not Working

Hi @mathewp

You can't use checked with livewire. You have to bind the inputs to an array (as you seem to be doing) and then on mount() method, populate that array with the options you fetch from database:

Maybe there is some easier way, but this is how I managed to make it work:

public function mount()
{
    $this->selections = array_fill_keys(User::with('permissions')
          ->find(1)  // just for testing purposes I'm hardcoding the ID to fetch
          ->permissions
          ->pluck('id')
          ->toArray(), 
        true);
}

Then at your view you have to use the dot notation to bind to an array, using the $perm->id as an index:

@foreach ($permissions as $perm)
    <div class="mt-1">
        <label class="inline-flex items-center">
        <input  wire:model="selections.{{$perm->id}}" type="checkbox"   
            class="w-6 h-6 text-green-500 form-checkbox "
         >
         <span class="ml-3 text-sm">{{ $perm->name }}</span> </input>
         </label> 
    </div>
@endforeach

You have to consider that if you check an option, and then un-check it again, you will have a false a the corresponding ID.

So before saving to database, you should filter the array to only keep those with a true value. Also, consider that the ID to persist to database, will be the key of the array instead of the value.

Hope this works for you!

Activity icon

Replied to Event.preventDefault()

Hi @rasoul_rezazadeh

Please share your code to see what could be wrong

Activity icon

Replied to How To Iterate Category Options Values With Edit Blade File In Laravel 6

Hi @flex

You don’t need the foreach at your controller:

public function edit($id)
    {
        $post = Post::find($id);
        $categories = Category::all();
        
        return view('posts.edit')->withPost($post)->withCategories($categories);
    }

And in your blade:

<div class="form-group">
    <label for="exampleFormControlSelect1">Category</label>

    <select class="form-control" name="category_id" id="category_id">
      @foreach($categories as $category)
      <option value="{{$category->id}}" {{ ($category->id == $post->category->id) ? 'selected' : ''}}>
          {{$category->name}}
      </option>
      @endforeach
      </select>

</div>

That should work

Nov
26
3 days ago
Activity icon

Replied to Error Class 'Swift_StreamFilters_StringReplacementFilter' Not Found

Hi @jimb814

From Inmotion page (https://www.inmotionhosting.com/shared-hosting)

Features include cPanel, FTP/SSH access, Softaculous application installer, and email creation and management.

So you should be able to connect via ssh to your server and then run the suggested commands to correctly deploy your application.

You'll probably have to enable and configure your ssh access from the cPanel (that it's included according to the shared-hosting specifications mentioned above)

Activity icon

Replied to Error Call To A Member Function Store() On Null

Hi @neeraj1005

This error also will happen if you submit your form before the file gets uploaded (which happens as soon as you choose a file).

So, consider adding a "loading" icon or label somewhere to test this, and if possible, disable the submit button while those loading states happen.

Activity icon

Replied to SQL Query

@hjortur17 Additional to @automica question, please share the bookings and services migrations, as well as some sample data from both tables.

Ideally, it would help if you can show those sample records along with the expected result from your query.

Activity icon

Awarded Best Reply on Component With Conditional Element

Hi @sarahs74

Please share the error that you get when it crashes

Nov
25
4 days ago
Activity icon

Replied to Sum Number In Vuejs

You're welcome @rod2rick !!

Please, don't forget to mark @rodrigo.pedra answer as the best answer in order to help others to find this solution!

Activity icon

Replied to Livewire Multiple Select

@mathewp regarding validation...as it's a selection list, it shouldn't be easy to have values that are not in the permissions table.

Anyway, for this case or future ones, you could try adding your rules like this at your component class:

    protected $rules = [
        'p' => 'exists:permissions',
    ];

then at the method that will save the info (submit or whatever):

    public function submit()
    {
        $this->validate();

        // Execution doesn't reach here if validation fails.

        // Here you will have the code that persists your data
    }

Docs:

https://laravel-livewire.com/docs/2.x/input-validation https://laravel.com/docs/8.x/validation#rule-exists

Activity icon

Awarded Best Reply on Livewire Multiple Select

@mathewp where exactly did you put this code: $this->permissions = Permission::all(); ?

I believe that should go inside the render() method.

Also, you should have a separate variable where to save the selected options, different from the one holding all the permissions to list on the dropdown. That separate variable is the one that you should bind to the <select>.

So you'll have something like this.

Component:

public $selection=[];

public function render() {
     return view('your-view', [
          'permissions' => Permission::all(),
     ]);
}

blade:

<select wire:model="selection" name="p" id="p" class="p" multiple>
    @foreach($permissions as $perm)
        <option value={{$perm->id}}>{{ $perm->name }}</option>
    @endforeach
</select>

See that I've added a value to the <option> as that's what it will populate the $selection array. Change the ->id to whatever the ID of the Permissions is

Activity icon

Replied to Livewire Multiple Select

Exactly @mathewp, I missed the curly braces! I've already corrected my previous answer (writing all this on the fly)

Glad it worked! Please remember to mark my answer so others can find the solution!

I'll answer your question about validation in another reply (probably later today)

Activity icon

Replied to Livewire Multiple Select

@mathewp where exactly did you put this code: $this->permissions = Permission::all(); ?

I believe that should go inside the render() method.

Also, you should have a separate variable where to save the selected options, different from the one holding all the permissions to list on the dropdown. That separate variable is the one that you should bind to the <select>.

So you'll have something like this.

Component:

public $selection=[];

public function render() {
     return view('your-view', [
          'permissions' => Permission::all(),
     ]);
}

blade:

<select wire:model="selection" name="p" id="p" class="p" multiple>
    @foreach($permissions as $perm)
        <option value={{$perm->id}}>{{ $perm->name }}</option>
    @endforeach
</select>

See that I've added a value to the <option> as that's what it will populate the $selection array. Change the ->id to whatever the ID of the Permissions is

Activity icon

Replied to Livewire Multiple Select

Hi @mathewp

If I understand correctly, you should have a public property at your component class set as an empty array:

public $multi = [];

Then at your blade you will have:

<select wire:model="multi" multiple>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

In order to test it, you can add in the same blade, a span / div / p tag...whatever with the following inside:

<div>
    {{ implode(' - ', $multi) }}
</div>

Hopefully this is what you wanted!

Activity icon

Replied to Add An Error To A Bag Without Redirecting

Anyway @grozavule

Why are you using a textbox to send more than 1 ID? You should allow to dynamically add a textbox for each ID and send them as an array, then you can use array validations:

https://laravel.com/docs/8.x/validation#validating-arrays

Activity icon

Replied to Add An Error To A Bag Without Redirecting

Hi @grozavule

You can manually create a validator with some basic rules:

https://laravel.com/docs/8.x/validation#manually-creating-validators

        $validator = Validator::make($request->all(), [
            'title' => 'required|unique:posts|max:255',
            'body' => 'required',
        ]);

Then you can add errors to the bag like this:

$validator->errors()->add('field', 'Something is wrong with this field!');

as explained in the section about After Validation Hook:

https://laravel.com/docs/8.x/validation#after-validation-hook

Hope this helps!

Activity icon

Replied to Cron Jon On Shared Hosting

Hi @nomi

It will depend on your hosting, but most of the times the path to your root folder is /home/USERNAME/ so your cron should be something like:

* * * * * cd /home/USERNAME && php artisan schedule:run >> /dev/null 2>&1

Anyway, if you have ssh you can find out the right path running a pwd while inside the root folder of your project.

Hope this helps

Activity icon

Replied to Sum Number In Vuejs

Yes @rodrigo.pedra

I've dealt with those same issues several times! But in this case, as the cart wasn't showing anything on a console.log (according to OP) I assumed that the error was somewhere else.

That's why I've created the codepen, to have a better chance to find the problem.

I should have started by asking to dump to console the products fetched with axios as a first step!

Activity icon

Replied to Sum Number In Vuejs

Good catch there @rodrigo.pedra !!

I didn't even think about numbers formatting...I've just assumed they should be coming as expected.

Activity icon

Replied to Sum Number In Vuejs

Unless your axios is returning a different object structure inside produits @rod2rick

Please, make a console.log(this.produits) at the end of the .then() method of your axios call and share here the result:

      axios
        .get("/api/produits")
        .then((response) => {
        this.produits = response.data.data;
        this.loading = false;
        console.log(this.produits);
      })
Activity icon

Replied to Sum Number In Vuejs

Well @rod2rick I don't know what other difference could you have in your implementation that makes it fail.

Have you checked out the codepen I've sent you? It works as you expect or am I missing something?

Activity icon

Replied to Sum Number In Vuejs

@rod2rick in that codepen, I've tested it both with Vue 2 and Vue 3 and works for both (despite some warnings and errors in console)

Activity icon

Replied to Sum Number In Vuejs

@rod2rick which version of Vue are you using?

Because it's working for me!

Here you have a working Codepen: https://codepen.io/mmoreyra/pen/MWjgRLg

I've just commented out the axios part and added a harcoded items list and I even added the itemTotalAmount() computed property.

Activity icon

Replied to Component With Conditional Element

Ok @sarahs74 !

So did my answer helped to solve your issue? If that's the case, please consider marking the question as answered.

Regarding your other question, I guess that's ok, or maybe you could include it as a subview

https://laravel.com/docs/8.x/blade#including-subviews

and use @includeWhen() instead...

Activity icon

Replied to SQL Query

It seems we all have been writing almost at the same time this time :D

Activity icon

Replied to Sum Number In Vuejs

@rod2rick so that's your problem...you don't seem to have a cart to sum, at least not available to this component.

Please share the rest of the javascript code of your component if possible

Activity icon

Replied to Component With Conditional Element

@sarahs74 then it doesn't seem to have anything to do with the Badge, as there is no code at all referencing a button variable in the code you've shared.

Please check in which file and line says that the error is occurring to see if we can narrow where the error is

Activity icon

Replied to SQL Query

@hjortur17 something like this maybe:

$garageToday = Booking::where('booking_type', '=', 'service')
	->where('dropOffDate', '=', $today)
        ->whereHas('services', function($query) {
                $query->where('category', 'like', 'garage');
            })
	->orderBy('dropOffTime')
	->with('services')
	->get();

hope this helps!

Activity icon

Replied to SQL Query

Hi @hjortur17

You should take a look to querying for relationship presences and how to constrain it:

https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-existence

Basically you need to use ->whereHas()

Activity icon

Replied to Component With Conditional Element

Hi @sarahs74

Please share the error that you get when it crashes

Activity icon

Replied to Laravel Throw Error Due To Another "From" Email

Glad to read that @greeenone !

Consider marking your answer as best answer to help others find the same solution

Activity icon

Replied to Laravel Throw Error Due To Another "From" Email

Hi @greeenone

I believe the error means you are not specifying a TO recipient

Activity icon

Awarded Best Reply on How To Update An Existing Array Of Items

@maximus1 I just saw that mark and reason are arrays, that's why you are getting that error.

Maybe something like this:

public function MarkStore(Request $request)
{
    $marks = $request->input('mark');
    $reasons = $request->input('reason');
    
    foreach($marks as $key => $mark) {
        QuestionAnswer::where('quiz', 1)
             ->where('user', 1)
             ->where('question_id', $key)
             ->update([
                'mark' => $mark,
                'reason' => $reasons[$key]
        ]);
    }
 } 

I'm assuming your Model has a question_id too, otherwise replace the corresponding where clause with the valid column id.

Hope this works, as I'm writing this on-the-fly.

Activity icon

Awarded Best Reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column

Actually now that I read again @marfino3028 that's not the problem.

For some reason, you have a query where it's saying that the id for the companies table is companies_id instead of just id

Activity icon

Replied to Base Table Or View Does Not Exist

Hi @gitwithravish

Just in case...did you run your migrations again after switching databases?

Nov
24
5 days ago
Activity icon

Replied to How To Update An Existing Array Of Items

@maximus1 if my last suggestion doesn't work, please share what do you get if you do a dd($request) just at the beginning of your MarkStore method

Activity icon

Replied to How To Update An Existing Array Of Items

@maximus1 I just saw that mark and reason are arrays, that's why you are getting that error.

Maybe something like this:

public function MarkStore(Request $request)
{
    $marks = $request->input('mark');
    $reasons = $request->input('reason');
    
    foreach($marks as $key => $mark) {
        QuestionAnswer::where('quiz', 1)
             ->where('user', 1)
             ->where('question_id', $key)
             ->update([
                'mark' => $mark,
                'reason' => $reasons[$key]
        ]);
    }
 } 

I'm assuming your Model has a question_id too, otherwise replace the corresponding where clause with the valid column id.

Hope this works, as I'm writing this on-the-fly.

Activity icon

Replied to How To Update An Existing Array Of Items

Hi @maximus1

It seems to me that you are wiling to do a mass update:

https://laravel.com/docs/8.x/eloquent#mass-updates

In your case I guess it should be something like:

public function MarkStore(Request $request)
{
    QuestionAnswer::where('quiz', 1)
        ->where('user', 1)
        ->update([
            'mark' => $request->input('mark'),
            'reason' => $request->input('reason')
        ]);
 } 

Hope this helps!

Activity icon

Awarded Best Reply on Fetch 02 Many To Many Tables & 01 HasOne Table

@ddsameera that's a dd() of $course after creating it?

What do you get if you dd($request)?

Also, at the ::create you have this

'meeting_id' > $meetingId

should be

'meeting_id' => $meetingId
Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column

Actually now that I read again @marfino3028 that's not the problem.

For some reason, you have a query where it's saying that the id for the companies table is companies_id instead of just id

Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column

Hi @marfino3028

If you've followed Eloquent conventions, the foreign key at employees should be company_id Please share the Migration where the employees table gets created.

Activity icon

Replied to Fetch 02 Many To Many Tables & 01 HasOne Table

@ddsameera that's a dd() of $course after creating it?

What do you get if you dd($request)?

Also, at the ::create you have this

'meeting_id' > $meetingId

should be

'meeting_id' => $meetingId
Activity icon

Replied to Fetch 02 Many To Many Tables & 01 HasOne Table

Hi @ddsameera

Please share the relationships with mainCategory, subCategory and meeting at your Course model, as well as an extract of a case of multiple meetings returned from that query.

Activity icon

Replied to Problem When Updating Resources

I'm glad it worked @warpig !!

The thing was that as you had different names on the route and your update parameters, it wasn't automatically binding the Post as expected.

That's why those 404 errors too.

Also, you were missing the save() method after assigning the changes... Now, you can go adding validation as I've first suggested:

public function update(Post $post, Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|max:255',
        'body'  => 'required',
        'slug'  => 'required',
    ]);

    $post->update($validatedData);

    return redirect('posts/' . $post->slug);
}

ref: https://laravel.com/docs/8.x/validation#quick-writing-the-validation-logic