Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

MarianoMoreyra

MarianoMoreyra

Member Since 4 Months Ago

Buenos Aires

Experience Points
81,870
Total
Experience

3,130 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
237
Lessons
Completed
Best Reply Awards
94
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 17
81,870 XP
Nov
25
45 minutes ago
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
1 day 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

Activity icon

Awarded Best Reply on Problem When Updating Resources

Actually, it's ok @warpig

If you edit the slug, it should change and not add a new one.

Please, try changing the update route to this:

Route::put('/posts/{post}', '[email protected]');

and see if it works...

Activity icon

Replied to Problem When Updating Resources

OR try changing your updatemethod to accept Post $slug instead of Post $post variable (Please just try one OR the other):

    public function update(Request $request, Post $slug)
    {   
        $post->title = request('title');
        $post->body = request('body');
        $post->slug = request('slug');

        $post->save();

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

Replied to Problem When Updating Resources

Actually, it's ok @warpig

If you edit the slug, it should change and not add a new one.

Please, try changing the update route to this:

Route::put('/posts/{post}', 'Pos[email protected]');

and see if it works...

Activity icon

Replied to Problem When Updating Resources

@warpig so you now have 2 posts with same slug ?

Activity icon

Replied to Problem When Updating Resources

I don't follow @warpig

Where do you say it's working? Did my last post worked and saved the updated post or not?

Activity icon

Replied to How To Save Requests From One Form And Then Pass Those Request To Another Form In Laravel?

@dr24 as @shrike said this behavior seems related to validation.

If you have some rule that is not passing, and you are not rendering errors at the first form view, you might be missing the reason why you are getting return to the first form.

Try temporary disabling validation at the first form controller and see what happens.

Activity icon

Replied to Problem When Updating Resources

@warpig I've just realized something...

Is this your entire Post model?

class Post extends Model
{
    public function getRouteKeyName()
    {
        return 'slug';
    }
    
    use HasFactory;
}

if that's the case, you need to add a $fillable or $guarded property to allow mass assignment.

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

Try with this for now:

class Post extends Model
{
    protected $guarded = [];

    public function getRouteKeyName()
    {
        return 'slug';
    }
    
    use HasFactory;
}

with the following update method:

    public function update(Request $request, Post $post)
    {   
        $post->title = request('title');
        $post->body = request('body');
        $post->slug = request('slug');

        $post->save();

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

EDIT: Changed the ->update() to ->save() and added reference to mass assignment on docs.

Activity icon

Replied to Problem When Updating Resources

Yes @warpig that should work provided that you have inputs with those names at your form.

Also, a cleaner way is the second example provided by @tray2 to which you could add some validation, following the offical docs, for example:

public function update(Post $post, Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|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

EDITED: tray2 said, you need the $post->update() after assigning values

Activity icon

Replied to Install Laravel Vue.js On Ubuntu

Hi @jhutto

Please share a bulleted list with a step-by-step detail of how did you implement at your server so it's easier to detect if you've missed a step.

Activity icon

Replied to Problem When Updating Resources

Hi @warpig

What are you getting back instead of an updated post? An error? The post without changes?

Just in case...your update method doesn't do anything at all with the post, so you should be getting the post as it was...

Or you haven't copied the code inside the update just to simplify?

If that's the case, please copy the entire code to see what could be going on

Activity icon

Replied to Sum Number In Vuejs

@rod2rick please share what do you get if you do

console.log(this.cart) 

Just before the return in the second case

Activity icon

Replied to Sum Number In Vuejs

Hi @rod2rick

It's difficult without seeing what you cart or item looks like, although inferring from what you've posted, you may try with something like this:

cartTotalAmount() {
      let total = 0;
      
      total = this.cart.reduce( (acc, item) => {
          return acc + (item.quantity * item.price)
      }, 0)

      return total;
    },

or if you want to simplify it a bit:

cartTotalAmount() {
    return this.cart.reduce( (acc, item) => {
        return acc + (item.quantity * item.price)
    }, 0)
}

Hope this works for you!

EDITED: I've added a second parameter to the reduce method in order to establish 0 as the initial value for the accumulator.

Nov
22
3 days ago
Activity icon

Awarded Best Reply on How To Use Multiple Date And Time Picker Inputs In Same Form Tempusdominus-bootstrap-4 Datetime Picker

Ok @sanjayacloud

There are several corrections / modifications to be explained here, so I took your code to a codepen and made it work there: https://codepen.io/mmoreyra/pen/VwjJyRG

Hopefully that's what you were looking for!!

If this works for you, please remember marking the question as answered.

Nov
21
4 days ago
Activity icon

Replied to Suddenly A New Question Is Ruby Markdown

@jlrdw Chrome both at my windows laptop and my iPhone and both look the same

Activity icon

Replied to Suddenly A New Question Is Ruby Markdown

Hi @jlrdw I see the questions like in your screenshot too. Basically without highlighting

Activity icon

Replied to How To Use Multiple Date And Time Picker Inputs In Same Form Tempusdominus-bootstrap-4 Datetime Picker

Ok @sanjayacloud

There are several corrections / modifications to be explained here, so I took your code to a codepen and made it work there: https://codepen.io/mmoreyra/pen/VwjJyRG

Hopefully that's what you were looking for!!

If this works for you, please remember marking the question as answered.

Activity icon

Awarded Best Reply on How Do I Schedule Some Code To Run At A Specific Time?

@reviewdevs you can still schedule a console command that runs every minute (or every 10 minutes...whatever) and that command can check the database for sessions that are not marked as attended and whose session end time has finished and the mark it as didnt_attend

Or maybe you could create a Job and queue it just after the Session gets created, scheduling it to be run when the session ends:

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

https://laravel.com/docs/8.x/queues#delayed-dispatching

although I don't think that's a good approach....as you'll have a lot of Jobs updating the database instead of just one massive update...

Also, I don't know if you can delay the dispatch of a Job by that much, specially after reading this warning:

The Amazon SQS queue service has a maximum delay time of 15 minutes.

Activity icon

Replied to How Do I Schedule Some Code To Run At A Specific Time?

@reviewdevs you can still schedule a console command that runs every minute (or every 10 minutes...whatever) and that command can check the database for sessions that are not marked as attended and whose session end time has finished and the mark it as didnt_attend

Or maybe you could create a Job and queue it just after the Session gets created, scheduling it to be run when the session ends:

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

https://laravel.com/docs/8.x/queues#delayed-dispatching

although I don't think that's a good approach....as you'll have a lot of Jobs updating the database instead of just one massive update...

Also, I don't know if you can delay the dispatch of a Job by that much, specially after reading this warning:

The Amazon SQS queue service has a maximum delay time of 15 minutes.

Activity icon

Replied to How Do I Schedule Some Code To Run At A Specific Time?

Hi @reviewdevs

Here is the doc for task scheduling: https://laravel.com/docs/8.x/scheduling

You may want to take a look to the frequency defining: https://laravel.com/docs/8.x/scheduling#schedule-frequency-options

Specially the ->dailyAt('19:00'); one to run the task each day at the specified hour

Hope this helps!

Activity icon

Awarded Best Reply on How Do I Track Things In A Many To Many Relationship

Hi @reviewdevs

Well, you have all what you need at official docs...

Here you can find how to retrieve additional columns from pivot tables: https://laravel.com/docs/8.x/eloquent-relationships#retrieving-intermediate-table-columns

Even customizing the name of the pivot table instead of accessing it as->pivot(): https://laravel.com/docs/8.x/eloquent-relationships#customizing-the-pivot-attribute-name

since it doesn't have an eloquent model Actually, you can define a Custom Model for intermediate tables if needed: https://laravel.com/docs/8.x/eloquent-relationships#defining-custom-intermediate-table-models

And finally, here you have some options regarding how to save data on those additional columns of your pivot tables: https://laravel.com/docs/8.x/eloquent-relationships#saving-additional-data-on-a-pivot-table

Hope this helps!

Activity icon

Awarded Best Reply on Constraining Eager Loads Not Working

Hi @marcelobianco

That's because you are constraining the eager loading of Empreendimento and not the query for SendFilesDocumentos.

I believe that you need to do a Query for Existence, using whereHas instead:

return view('livewire.documentos', [ 'docs' => SendFilesDocumentos::whereHas(['empreendimento' => function ($query) { $query->where('id_empreendimento', '1'); }])->get(), ]);

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

Hope this helps!

Nov
20
5 days ago
Activity icon

Replied to How Do I Track Things In A Many To Many Relationship

Hi @reviewdevs

Well, you have all what you need at official docs...

Here you can find how to retrieve additional columns from pivot tables: https://laravel.com/docs/8.x/eloquent-relationships#retrieving-intermediate-table-columns

Even customizing the name of the pivot table instead of accessing it as->pivot(): https://laravel.com/docs/8.x/eloquent-relationships#customizing-the-pivot-attribute-name

since it doesn't have an eloquent model Actually, you can define a Custom Model for intermediate tables if needed: https://laravel.com/docs/8.x/eloquent-relationships#defining-custom-intermediate-table-models

And finally, here you have some options regarding how to save data on those additional columns of your pivot tables: https://laravel.com/docs/8.x/eloquent-relationships#saving-additional-data-on-a-pivot-table

Hope this helps!

Activity icon

Replied to Modal Open In Dark Area,Stuck

@ddsameera it probably has to do with the solution provided at Stack Overflow:

If the modal container has a fixed or relative position or is within an element with fixed or relative position this behavior will occur.

and when you include the modal within the section block, it gets affected by a container with fixed or relative positioning.

Have you checked for something like that?

Activity icon

Replied to Modal Open In Dark Area,Stuck

@ddsameera any chance that it's conflicting with any other modal at they layout page/component where that @section('content') is getting rendered?

Activity icon

Replied to Modal Open In Dark Area,Stuck

Hi @ddsameera

Have you checked your console for errors?

Activity icon

Replied to Constraining Eager Loads Not Working

You can add Eager Loading too if you need it...I've just replaced it for simplicity...

Activity icon

Replied to How To Use Multiple Date And Time Picker Inputs In Same Form Tempusdominus-bootstrap-4 Datetime Picker

Hi @sanjayacloud

So this reply from your other post didn't help you to have multiple date time pickers? https://laracasts.com/discuss/channels/javascript/how-to-use-multiple-date-and-time-picker-inputs-in-same-form-bootstrap-datetimepicker?page=1#reply=666184

I even provided you a working codepen. I've just read that you wanted only time picker and not date time...the same idea from my reply applies to just time pickers...

Did you try my suggestion at least?

Let me know if you need more details to make it work.

Activity icon

Replied to Constraining Eager Loads Not Working

Hi @marcelobianco

That's because you are constraining the eager loading of Empreendimento and not the query for SendFilesDocumentos.

I believe that you need to do a Query for Existence, using whereHas instead:

return view('livewire.documentos', [ 'docs' => SendFilesDocumentos::whereHas(['empreendimento' => function ($query) { $query->where('id_empreendimento', '1'); }])->get(), ]);

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

Hope this helps!

Activity icon

Awarded Best Reply on Flash Message After $this->validate()

Oh ok @nicolasj

I see what you mean now.

The thing is, you won't be able to flash anything after the $this->validate() because that statement will automatically return to the view with the errors.

So you could use a custom validator, and call the validate() method after flashing your message as intended.

For example:

public function submit()
{
    $validator = Validator::make(
        [
            'name'  => $this->name,
            'email' => $this->email,
        ],
        [
            'name'  => 'required|min:6',
            'email' => 'required|email',
        ]
    );

    if ($validator->fails()) {
        session()->flash('custom_message', 'Oops! Something went wrong...');
    } 
    
    $validator->validate();
}

That made the job in my case.

I believe that @snapey solution will work if you adapt it to a custom validator too, as you mentioned that you use dispatchBrowserEvent as he suggest.

So in that case, you'll just dispatch the browser event instead of doing a session()->flash() like in my example.

Hope this is what you were looking for!

Activity icon

Replied to Flash Message After $this->validate()

Also @nicolasj

To avoid validating twice, you could just throw a ValidationException:

public function submit()
{
    $validator = Validator::make(
        [
            'name'  => $this->name,
            'email' => $this->email,
        ],
        [
            'name'  => 'required|min:6',
            'email' => 'required|email',
        ]
    );

    if ($validator->fails()) {
        session()->flash('custom_message', 'Oops! Something went wrong...');

        throw new ValidationException($validator);
    } 
}

since that's basically what the validate() method does inside, besides triggering all the rules, which in this case we just step over:

public function validate()
{
    if ($this->fails()) {
        throw new ValidationException($this);
    }

    return $this->validated();
}

In the validate() case, as you see it calls $this->fails() which ultimately runs all the rules, which we already did before so it's not necessary and we can just throw the exception...

Couldn't get to try it but I believe this should work too....

Activity icon

Replied to Flash Message After $this->validate()

Great to hear @nicolasj !!

Please remember marking the question as answered to help others find this solution

Nov
19
6 days ago
Activity icon

Awarded Best Reply on Laravel Jetstream Ignore Routes Not Working

Hi @bufferoverflow

Try moving Jetstream::ignoreRoutes(); to the register method of you AppServiceProvider as one user mentioned at the comments of the PR that have added this option.

ref: https://github.com/laravel/jetstream/pull/67#issuecomment-708327758

Hope this helps!

Activity icon

Replied to Laravel Jetstream Ignore Routes Not Working

Hi @bufferoverflow

Try moving Jetstream::ignoreRoutes(); to the register method of you AppServiceProvider as one user mentioned at the comments of the PR that have added this option.

ref: https://github.com/laravel/jetstream/pull/67#issuecomment-708327758

Hope this helps!

Activity icon

Replied to Laravel Trying To Get Property Of Non-object

That's strange @pordonez

Are you sure that's the line throwing the error? Any chance that the error is somewhere else?

If you try hardcoding the department assignment like:

$ticket->department = "Some department";
$ticket->save();

it works?

Activity icon

Replied to Laravel Trying To Get Property Of Non-object

Hi @pordonez

You have tested using dd() just before assigning to $ticket->department?

Please share the full code (at least the context where all this is happening) to see if we can spot anything weird.

Activity icon

Replied to Laravel Eloquent Belongs To Many Query Returns Entries Multiple Time

@frazecolder traducing this to Eloquent it should be something similar to this I believe:

$products = ProductsMark::select('products.*')
    ->join('products', 'products_marks.product_id', '=', 'products.id')
    ->where('products_marks.user_id', $user->id)
    ->where('page_status_id', PageStatus::getIdByStatus('publish'))
    ->orWhere(function($query) use ($user){
                $query->where('page_status_id', PageStatus::getIdByStatus('pending'))
                    ->where('products.user_id', $user->id);
        })
     ->orderBy('products_marks.created_at', 'desc')
     ->paginate(10);

Most probably this won't work as I'm writing this on-the-fly, but you'll surely get the idea! :)

Activity icon

Replied to Laravel Eloquent Belongs To Many Query Returns Entries Multiple Time

Hi @frazecolder

With that query, that's the expected result as you are joining products first, with products_marks, so in this case, for each product in products table, it will bring ALL the corresponding records that match on products_marks, duplicating the info from products table.

So, in this case, you should start your query from the products_marks table and then join with products. If you try with this query you'll see it works as expected:

select `products`.* 
from `products_marks` 
inner join `products` on `products_marks`.`product_id` = `products`.`id` 
where ((`products_marks`.`user_id` = 19) 
  and (`page_status_id` = 1) 
   or (`page_status_id` = 4 and `products`.`user_id` = 19))
order by `products_marks`.`id` desc limit 10 offset 0

Hope this makes sense to you! Otherwise let me know and I'll see if I can come with a better explanation!