MarianoMoreyra

MarianoMoreyra

Member Since 2 Months Ago

Buenos Aires

Experience Points
39,280
Total
Experience

720 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
108
Lessons
Completed
Best Reply Awards
47
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 8
39,280 XP
Sep
22
21 hours ago
Activity icon

Awarded Best Reply on Accessing Model Properties In Scope

Hi @expdev07

If I understand correctly what you need, maybe you could try comparing directly to the post user_id field, like this:

    public function scopeNotBlocked($query, User $user): Builder
    {
        // Query for posts where creator has not blocked the provided user or the user has blocked the creator.
        return $query->whereDoesntHave('user.blocks', function (Builder $query) use ($user) {
            $query
                ->where('user_id', 'posts.user_id')
                ->orWhere('blocked_id', $user->id);
        });
    }

As you can see, I'm assuming that your Posts table is named posts and that the creator foreign key is user_id

Hope this helps!

Activity icon

Awarded Best Reply on A Better Way?

Hi @alexsteele

Could you show some code of what you've got so far? I'm not quite understanding what you are trying to do, and specially don't understand why you have those records mapped onto 10 variables, but smells like something might be wrong there.

Anyway, if you need to have those values in variables, you better keep them in an array, so in this case you could to the matching you need by doing something like:

User::with(['options' => function ($query) use ($options) {
    $query->whereIn('option_id', $options);
}])->get();

Ref:

https://laravel.com/docs/8.x/eloquent-relationships#constraining-eager-loads https://laravel.com/docs/8.x/queries#where-clauses

But again, we might need to see some code to better assist

Activity icon

Replied to Regex Validation In Laravel(getting This Error (preg_match(): Delimiter Must Not Be Alphanumeric Or Backslash))

Hi @onsoftadilsonjose

Try the following:

    'nif' => ['required', 'regex:/\d{9}[A-Z]{2}\d{3}/']

Hope this helps

Activity icon

Replied to A Better Way?

Hi @alexsteele

Could you show some code of what you've got so far? I'm not quite understanding what you are trying to do, and specially don't understand why you have those records mapped onto 10 variables, but smells like something might be wrong there.

Anyway, if you need to have those values in variables, you better keep them in an array, so in this case you could to the matching you need by doing something like:

User::with(['options' => function ($query) use ($options) {
    $query->whereIn('option_id', $options);
}])->get();

Ref:

https://laravel.com/docs/8.x/eloquent-relationships#constraining-eager-loads https://laravel.com/docs/8.x/queries#where-clauses

But again, we might need to see some code to better assist

Activity icon

Replied to Laravel Component Problem.

Hi @sagar001

Try adding user as a prop at your component, that way, it should be catch as a prop instead of going to the attribute bag

Activity icon

Replied to SQLSTATE[23502]: Not Null Violation: 7 ERROR: Null Value In Column "user_id" Violates Not-null Constraint

@alex_b that’s strange, because if you see the error it’s not just the id that’s passing as null but all the custom fields.

Could you post your Season model?

Activity icon

Replied to SQLSTATE[23502]: Not Null Violation: 7 ERROR: Null Value In Column "user_id" Violates Not-null Constraint

Hi @alex_b

Have you set the $fillable or $guarded properties in your Season model in order to be able to do mass assignment?

If not, add the following to Season model:

protected $guarded = [];

And see if it works

EDITED

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

Activity icon

Replied to How To Include User Id In $validated Create?

You are right @michaloravec !!

Don’t know why I skipped @thewebartisan7 reply!!

My bad!

Activity icon

Replied to How To Include User Id In $validated Create?

Although I think I like @sinnbeck solution better, as you don't actually need to include the user_id in the validation, just returning it at the end would be enough.

Activity icon

Replied to How To Include User Id In $validated Create?

Hi @martinzeltin

Well, you could do an array_merge and pass that to your function instead of using the request() internally.

So you'll end up with something like this

public function store(Request $request)
{
    $validated = $this->validateThread(array_merge(
        request(), 
        ['user_id' => auth()->id()]
    ));

    $thread = Thread::create($validated);
}

and then in your function:

public function validateThread($fields)
{
    $validated = $this->validate($fields, [
	'user_id' => 'required',
        'title' => 'required',
        'body' => 'required',
        'channel_id' => 'required|exists:channels,id',
    ]);

    resolve(Spam::class)->detect(request('body'));

    return $validated;
}

Does that make sense?

Activity icon

Replied to Failed To Open Stream: No Such File Or Directory

Hi @webfuelcode

It seems like you might have a typo somewhere?

You are missing an s in Composer according to this error:

include<C:...................laravel/framework/src/illuminate/Foundation/Providers/CompoerServiceProvider.php
Activity icon

Replied to .htaccess Error

As @sinnbeck asked, it’s important to know if the error is thrown at console or when browsing.

In case it’s browsing @davy_yg you should try adding the line I’ve suggested at your .htaccess file

In case it’s at console, you should try running php with the full path to the 7.3 (or 7.2) version

Activity icon

Replied to .htaccess Error

@laracoft line 34 on that file is this:

function v1($node = null, ?int $clockSeq = null): string

The only ? There is the nullable introduced in php 7.1 That’s why I’ve been insisting on the php version

Activity icon

Awarded Best Reply on How To Count Product With Respect To Categories Using Query Builder?

Hi @saurav77

You could define a hasThrough relationship between Category and Product adding the following to your Category Model::

    public function products()
    {
        return $this->hasManyThrough('App\Models\Product', 'App\Models\Brand');
    }

So then you can use withCount in your query to get the Product count for each Category:


$categories = App\Models\Category::withCount('products')->get();

Of course I’m assuming your Models’ names as well as that you have them placed inside a Models folder.

Si you’ll have to change that in my example to make it work probably.

Refs:

https://laravel.com/docs/master/eloquent-relationships#has-many-through https://laravel.com/docs/master/eloquent-relationships#counting-related-models

Hope this helps!

Activity icon

Replied to .htaccess Error

@davy_yg ok...if you are absolutely sure that's the only PHP version your server is running, then I'm out of ideas at this moment (2:45 am here hehe).

Hope you find the problem and sorry for the insistence :)

Activity icon

Replied to .htaccess Error

@davy_yg in case it effectively shows an older version, you can try adding the following at the top of your .htaccess file:

AddHandler application/x-httpd-php73 .php .php5

to force that version for that particular folder / webapp

Activity icon

Replied to .htaccess Error

Just in case, throw a .php file with a call to phpinfo() in it and browse that file to see which PHP version shows.

I had this same problem with a server, which even verifying that it was configured to run with the latest PHP version available at that time, as it had different versions installed, for some reason the phpinfo() showed that the webserver for that particular domain was running PHP v5.x

Activity icon

Replied to How To Count Product With Respect To Categories Using Query Builder?

@saurav77 at first glance that query looks like it should work (except for the "category" at the select, which I guess it should be "category_name" based on your tables description).

But if you think the results are not accurate, then you'll have to post more information in order to be able to help you.

For instance, and example with data, expected result and current result obtained might be helpful.

Activity icon

Replied to .htaccess Error

Hi @davy_yg

That's probably a problem with your PHP version. Check that you are using version >= 7.2.5.

If you've deploy on a shared hosting with cPanel, you can usually can easily change the PHP version from there, although you might need to do some other change on .htaccess to be sure that your web application is using the same version.

Activity icon

Replied to HasOneThrough Confusion

@guyinpv it will depend on what are you trying to achieve.

Assuming you have the corresponding belongsTo relationship on each Model like this:

User:

    public function car() {
        return $this->belongsTo(Car::class);
    }

Car:

    public function maker() {
        return $this->belongsTo(Maker::class);
    }

You can simply get the maker by doing, for example:

$user = User::with('car.maker')->find($user_id);

$maker = $user->car->maker;

Although I'm not sure if this is what you are asking for...

Sep
21
1 day ago
Activity icon

Replied to HasOneThrough Confusion

That's right, you don't have to change the Car table to a pivot table, and you don't need to do it that way.

Activity icon

Replied to HasOneThrough Confusion

Hi @guyinpv

Laravel doesn't includes the inverse belongsToThrough relationship in this case. So, you'll have to add the belongsTo relationship to each Model and then get the maker by traversing the models in the standard way.

Or, you can try adding a third-party package like this one, that allows you to use a belongsToThrough relationship: https://github.com/staudenmeir/belongs-to-through

It seems to be maintained, although you should always keep in mind that it's not an official package, so you should use it at your own risk!

Activity icon

Replied to How To Count Product With Respect To Categories Using Query Builder?

No problem @saurav77

Just got confused because your post was under Eloquent category so I assumed that you wanted to resolve it, the Eloquent way hehe.

Regarding the query that you already tried, what you mean by "not getting result"? You don't get anything at all? You get an error? You get an count that doesn't mach the expected on?

Activity icon

Replied to Multiple File Uploads Validation Problem

I'm kind of confused @bojan1994

On you original post you said:

I succeeded to validate second field easily, but first always passes. Strange thing is, when i modify first input to be type="text" rather then type="file", everything works.

But now you say it only works when it's not an array?

So, when you change it from file to text, it doesn't work either if it's an array?

Please, share the entire Form, including the foreach statement that creates the array.

Activity icon

Replied to Multiple File Uploads Validation Problem

Hi @bojan1994

Check that you have included enctype="multipart/form-data” to your form.

Sep
20
2 days ago
Activity icon

Awarded Best Reply on Testing Artisan Commands When Developing Vendor Packages

Hi @automica !

I see you are using a Unit Test, in which case you should check that you are not extending the PHPUnit TestCase instead of the Laravel one.

In my case at least, the Unit Tests are created with the following:

use PHPUnit\Framework\TestCase;

so you have to change it to use the Laravel one:

use Tests\TestCase;

Otherwise you won't have access to artisan method

Hope that's it!

Activity icon

Awarded Best Reply on Scope Method Is Not Found On Related Model

Hi @martinzeltin

Try adding a () to the subscriptions call otherwise you are trying to call the scope on a resulting Collection instead of the Relatuonship:

$this->subscriptions()->notFor($reply->user_id)->each->notify($reply); 

Hope this works!

Activity icon

Replied to Scope Method Is Not Found On Related Model

Hi @martinzeltin

Try adding a () to the subscriptions call otherwise you are trying to call the scope on a resulting Collection instead of the Relatuonship:

$this->subscriptions()->notFor($reply->user_id)->each->notify($reply); 

Hope this works!

Activity icon

Replied to Testing Artisan Commands When Developing Vendor Packages

Hi @automica !

I see you are using a Unit Test, in which case you should check that you are not extending the PHPUnit TestCase instead of the Laravel one.

In my case at least, the Unit Tests are created with the following:

use PHPUnit\Framework\TestCase;

so you have to change it to use the Laravel one:

use Tests\TestCase;

Otherwise you won't have access to artisan method

Hope that's it!

Activity icon

Replied to How To Count Product With Respect To Categories Using Query Builder?

Hi @saurav77

You could define a hasThrough relationship between Category and Product adding the following to your Category Model::

    public function products()
    {
        return $this->hasManyThrough('App\Models\Product', 'App\Models\Brand');
    }

So then you can use withCount in your query to get the Product count for each Category:


$categories = App\Models\Category::withCount('products')->get();

Of course I’m assuming your Models’ names as well as that you have them placed inside a Models folder.

Si you’ll have to change that in my example to make it work probably.

Refs:

https://laravel.com/docs/master/eloquent-relationships#has-many-through https://laravel.com/docs/master/eloquent-relationships#counting-related-models

Hope this helps!

Sep
19
3 days ago
Activity icon

Replied to Trying To Perform Migration "Illuminate\Database\QueryException"

Hi @monstajamss

Seems like you don't have a table defined at the config file where you are trying to get it, so this line it must be returning an empty string:

config('eloquent-viewable.models.view.table_name')

Take a look at that config file and see if you've misspelled the name of a folder of the variable itself

Activity icon

Replied to Help Building A Query Or Using Eloquent

Hi @schwartzmj

You are Eager Loading the relationship there, so you shouldn't need to go to database again.

Maybe it's not the nicest way, but if you can only get 1 application per year, then you can just take the first() element from the collection:

<td>
    @if ($family->applications->isNotEmpty())
            {{ $family->applications->first()->status }}
    @else
        Not Created
    @endif
</td>

or maybe you can make it shorter like this:

<td>
        {{ $family->applications->first()->status ?? "Not Created" }}
</td>
Sep
18
4 days ago
Activity icon

Replied to Relationships With A "type" Of Relationship

Hi @lmangold@outlook.com

I’m not sure if I understand your need, although it really seems to me that what you are needing is a Polymorphic Relationship: https://laravel.com/docs/master/eloquent-relationships#one-to-one-polymorphic-relations

Hope that’s it!

Activity icon

Replied to Get Model Items Included In Relationship (categories That Have Products)

@msslgomez actually, reading again, you should use whereHas instead so you can filter the Products using a whereIn and passing your $products list.

Sorry I can’t write an example for you, as I’m at my phone and it gets hard to write that code hehe

Activity icon

Replied to Jeffrey's Test Setup

Hi @justageek

If I’m not wrong, Jeffry uses Valet (only available for Mac users) which allows to create new virtual hosts easily for each new project.

If you are a Windows user, you can use Homestead, or Laragon, similar to Valet.

I'd recommend Laragon if you want to have your projects quickly up and running and with less resources using than Homestead.

Sep
17
5 days ago
Activity icon

Replied to X-component : Cannot Pass Variable In <>

That’s great @jntng

Glad I was able to help!!

Activity icon

Awarded Best Reply on X-component : Cannot Pass Variable In <>

Hi @jntng

Your code should work as is, unless it's not an anonymous component, in which case you have to declare the $title as a public attribute at your Layout class and pass it to the constructor.

If it's indeed an anonymous component, the title should be there. Have you trying inspecting the source code of the resulting page to see if it's there but hidden for some reason?

Sep
16
6 days ago
Activity icon

Replied to X-component : Cannot Pass Variable In <>

Hi @jntng

Your code should work as is, unless it's not an anonymous component, in which case you have to declare the $title as a public attribute at your Layout class and pass it to the constructor.

If it's indeed an anonymous component, the title should be there. Have you trying inspecting the source code of the resulting page to see if it's there but hidden for some reason?

Activity icon

Awarded Best Reply on How To Make Query For Fetching Specific Id In Eloquent Many To Many?

Hi @mimiloca

You are not specifying any club id in your Eloquent query.

If you want to get the club with id 2 you should do:

$clubs = Club::with('members')->where('id', 2)->get();

Although, you should pass the id to your show method:

public function show($id)
{
    $clubs = Club::with('members')->where('id', $id)->get();

    return view('club.member')->with('club', $clubs); 
}

and update your route to pass that variable

Activity icon

Replied to How To Make Query For Fetching Specific Id In Eloquent Many To Many?

Hi @mimiloca

You are not specifying any club id in your Eloquent query.

If you want to get the club with id 2 you should do:

$clubs = Club::with('members')->where('id', 2)->get();

Although, you should pass the id to your show method:

public function show($id)
{
    $clubs = Club::with('members')->where('id', $id)->get();

    return view('club.member')->with('club', $clubs); 
}

and update your route to pass that variable

Activity icon

Replied to When I Required Selectize Js In Laravel Mix It Get Me Error Is Not A Function

Hi @hasanhatem

You have a typo. It's not required, it's require:

require('selectize');
Sep
15
1 week ago
Activity icon

Replied to Accessing Model Properties In Scope

Hi @expdev07

If I understand correctly what you need, maybe you could try comparing directly to the post user_id field, like this:

    public function scopeNotBlocked($query, User $user): Builder
    {
        // Query for posts where creator has not blocked the provided user or the user has blocked the creator.
        return $query->whereDoesntHave('user.blocks', function (Builder $query) use ($user) {
            $query
                ->where('user_id', 'posts.user_id')
                ->orWhere('blocked_id', $user->id);
        });
    }

As you can see, I'm assuming that your Posts table is named posts and that the creator foreign key is user_id

Hope this helps!

Activity icon

Replied to How To Use OrgChart JS In Vue

Hi @tarang19

Have you try following the steps recommended at their documentation?

docs: https://balkangraph.com/OrgChartJS/Docs/Vuejs

Hope this helps!

Sep
14
1 week ago
Activity icon

Replied to Help With Filter Using Pipelines. Laravel 7

Hi @ajsmith_codes

Just to be sure, your requested_ship_date field is a Date, DateTime or Timestamp field right?

Also, you are not copying your entire Filter base class...just the handle method...so I guess you just left that second return statement by mistake?

Finally, could you please copy the url you are using? Are just using the same as the example like this?

http://127.0.0.1:8000/post?active=1&sort=desc&max_count=1

Activity icon

Replied to Return View Dost'nt Work

You're welcome @hendrasaputra2323 !!

Glad I was able to help!

Activity icon

Replied to Return View Dost'nt Work

@hendrasaputra2323 I just saw this:

This my href to acces link

href="{{ route('tag.update', $hasil->id ) }}">

So you should change that to

href="{{ route('tag.edit', $hasil->id ) }}">

as I said before, as that route is the one that you should hit from your edit form to actually save the changes

Activity icon

Awarded Best Reply on Return View Dost'nt Work

Well @hendrasaputra2323, because a translation problem, I'm not sure which one is your Edit button in that code, but if it's this:

<a class="flex items-center mr-3" href="{{ route('tag.update', $hasil->id ) }}"> <i data-feather="check-square" class="w-4 h-4 mr-1"></i> Ubah </a>

Maybe you should change the route to the update one, like this:

<a class="flex items-center mr-3" href="{{ route('tag.edit', $hasil->id ) }}"> <i data-feather="check-square" class="w-4 h-4 mr-1"></i> Ubah </a>

Although I could be missing something else out

Activity icon

Replied to Return View Dost'nt Work

Well @hendrasaputra2323, because a translation problem, I'm not sure which one is your Edit button in that code, but if it's this:

<a class="flex items-center mr-3" href="{{ route('tag.update', $hasil->id ) }}"> <i data-feather="check-square" class="w-4 h-4 mr-1"></i> Ubah </a>

Maybe you should change the route to the update one, like this:

<a class="flex items-center mr-3" href="{{ route('tag.edit', $hasil->id ) }}"> <i data-feather="check-square" class="w-4 h-4 mr-1"></i> Ubah </a>

Although I could be missing something else out