belipero

belipero

Member Since 3 Years Ago

Experience Points
3,810
Total
Experience

1,190 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
34
Lessons
Completed
Best Reply Awards
0
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 1
3,810 XP
Apr
07
18 hours ago
Activity icon

Started a new Conversation Count Of Two Tables Considering Group By

Hi! I'm developing a classic Top 10 table and I'm getting the expected results with the following code:

$top10offerdemandsbyagent = DB::table('offerdemands')
	->leftJoin('users', 'offerdemands.email', '=', 'users.email')
	->select(DB::raw('count(*) as total, users.name, users.avatar'))
	->groupBy('users.name', 'users.avatar')
	->orderBy('total', 'desc')
	->take(10)
	->get()->toArray();

This code is generating the followins SQL statemente:

select
  count(*) as total,
  users.name,
  users.avatar
from
  `offerdemands`
  left join `users` on `offerdemands`.`email` = `users`.`email`
group by
  `users`.`name`,
  `users`.`avatar`
order by
  `total` desc
limit
  10

I need to add an additional table called offerdemandsmatchs which is a child related table 1:M with offerdemands table and count the total records of this child related table and expose that value in selectin order to use it in blade.

Does anyone can help me on this?

Regards

Mar
31
1 week ago
Activity icon

Replied to Collections - Filter Child Relationship If Field Is Null

@tykus thanks for your help, I changed code as follows and now it's working

public function details($id)
    {
        $property = Property::with(['attributes' => function ($builder) {
            $builder->where('pa_value', '!=', '');
        }])
            ->with('addons', 'distributions', 'images', 'attributes_2', 'services')
            ->where('prop_id', $id)
            ->withCount('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
            ->first();
        dd($property);
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
Activity icon

Replied to Collections - Filter Child Relationship If Field Is Null

The SQL extracted is:

select
  *
from
  `property_attributes`
where
  `property_attributes`.`property_id` in (1804)
  and `pa_value` is not null

And the query that returns the expected results directly executed in database is:

select
  *
from
  `property_attributes`
where
  `property_attributes`.`property_id` in (1804)
  AND `pa_value` != ''
Activity icon

Replied to Collections - Filter Child Relationship If Field Is Null

Thanks @tykus , sorry that was something I could catch.

The result is that records are not filtered as you can see below, perhaps it's a data issue that I have to consider 2 condtions: is null or !=''

App\Property {#496 ▼
  #connection: "mysql"
  #table: "properties"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:39 [▶]
  #original: array:39 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: array:6 [▼
    "attributes" => Illuminate\Database\Eloquent\Collection {#527 ▼
      #items: array:20 [▼
        0 => App\PropertyAttribute {#534 ▶}
        1 => App\PropertyAttribute {#541 ▼
          #connection: "mysql"
          #table: "property_attributes"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:8 [▼
            "id" => 40536
            "property_id" => 1804
            "pa_title" => "Superficie Descubierta"
            "pa_code" => "superficie_descubierta"
            "pa_value" => ""
            "pa_unit" => "m2"
            "pa_position" => "posterior"
            "pa_order" => 15
          ]
          #original: array:8 [▶]
          #changes: []
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #dispatchesEvents: []
          #observables: []
          #relations: []
          #touches: []
          +timestamps: true
          #hidden: []
          #visible: []
          #fillable: []
          #guarded: array:1 [▶]
        }
        2 => App\PropertyAttribute {#531 ▶}
        3 => App\PropertyAttribute {#540 ▶}
        4 => App\PropertyAttribute {#543 ▶}
        5 => App\PropertyAttribute {#542 ▶}
        6 => App\PropertyAttribute {#536 ▶}
        7 => App\PropertyAttribute {#538 ▶}
        8 => App\PropertyAttribute {#537 ▶}
        9 => App\PropertyAttribute {#532 ▶}
        10 => App\PropertyAttribute {#539 ▶}
        11 => App\PropertyAttribute {#544 ▶}
        12 => App\PropertyAttribute {#545 ▶}
        13 => App\PropertyAttribute {#546 ▶}
        14 => App\PropertyAttribute {#547 ▶}
        15 => App\PropertyAttribute {#548 ▶}
        16 => App\PropertyAttribute {#549 ▶}
        17 => App\PropertyAttribute {#550 ▶}
        18 => App\PropertyAttribute {#551 ▶}
        19 => App\PropertyAttribute {#552 ▶}
      ]
    }
    "addons" => Illuminate\Database\Eloquent\Collection {#511 ▶}
    "distributions" => Illuminate\Database\Eloquent\Collection {#533 ▶}
    "images" => Illuminate\Database\Eloquent\Collection {#554 ▶}
    "attributes_2" => Illuminate\Database\Eloquent\Collection {#515 ▶}
    "services" => Illuminate\Database\Eloquent\Collection {#555 ▶}
  ]
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▶]
}
Activity icon

Replied to Collections - Filter Child Relationship If Field Is Null

Thanks @tykus

The code you shared throws the same SQL error as before: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'attributes.pa_value' in 'where clause'

public function details($id)
    {
        $property = Property::with(['attributes' => function ($builder) {
            $builder->whereNotNull('attributes.pa_value');
        }])
            ->with('addons', 'distributions', 'images', 'attributes_2', 'services')
            ->where('prop_id', $id)
            ->withCount('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
            ->first();
        dd($property);
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }

It's possible that this can be related to parent model definition?

public function attributes() {
	return $this->hasMany(PropertyAttribute::class);
	}
Activity icon

Started a new Conversation Collections - Filter Child Relationship If Field Is Null

Hi! I have a controller method that returns a model with it's relationships (1:M) All child records are returned but I want to don't reterieve child record from a particular model which has a null field.

I'm trying to use whereNotNull for filtering the child table column but it looks i'm not passing correctly the refernce to it: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'attributes.pa_value' in 'where clause'

How can I not retrieve those child records which has a null value in a column?

Controller

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::with('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
                    ->where('prop_id', $id)
                  //  ->whereNotNull('attributes.pa_value')
                    ->withCount('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
                    ->first();
        dd($property);
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }


}
Mar
30
1 week ago
Activity icon

Awarded Best Reply on Bootstrap Modal Open With Record Details

Hi! I finally got my code fixed and it's working, i'm sharing the solution:

Button Code (it's important to remove data-target property)

<button type="button"
	class="btn btn-label-primary btn-lg btn-upper openBtn"
	data-toggle="modal"
	data-id = {!! $match->prop_id !!}>
	{{ __('pages/processes/offerdemand.labels.matchs.index.button.viewproperty') }}
</button>

JS Code

$(document).ready(function () {
    $('.openBtn').on('click', function () {

        var prop_id = $(this).data('id');
        console.log(prop_id);

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
                type: 'GET',
                url: '/property/details/' + prop_id,
                dataType: 'HTML',

                success: function (data) {

                },
            }).then(data => {
                $('.modal-content').html(data);
                $('#kt_modal_4_2').modal("show");
            })
            .catch(error => {
                var xhr = $.ajax();
                console.log(xhr);
                console.log(error);
            })

    });
});

Controller Code

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::with('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
                    ->where('prop_id', $id)
                    ->first();
        // dd($property);
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
}

The view returned from Controller has it's first element <div class="modal-content"> which has modal HTML code.

Activity icon

Replied to Bootstrap Modal Open With Record Details

Hi! I finally got my code fixed and it's working, i'm sharing the solution:

Button Code (it's important to remove data-target property)

<button type="button"
	class="btn btn-label-primary btn-lg btn-upper openBtn"
	data-toggle="modal"
	data-id = {!! $match->prop_id !!}>
	{{ __('pages/processes/offerdemand.labels.matchs.index.button.viewproperty') }}
</button>

JS Code

$(document).ready(function () {
    $('.openBtn').on('click', function () {

        var prop_id = $(this).data('id');
        console.log(prop_id);

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
                type: 'GET',
                url: '/property/details/' + prop_id,
                dataType: 'HTML',

                success: function (data) {

                },
            }).then(data => {
                $('.modal-content').html(data);
                $('#kt_modal_4_2').modal("show");
            })
            .catch(error => {
                var xhr = $.ajax();
                console.log(xhr);
                console.log(error);
            })

    });
});

Controller Code

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::with('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
                    ->where('prop_id', $id)
                    ->first();
        // dd($property);
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
}

The view returned from Controller has it's first element <div class="modal-content"> which has modal HTML code.

Mar
27
1 week ago
Activity icon

Replied to Bootstrap Modal Open With Record Details

Thanks @sti3bas

My problem is that code is not working, modal is not opening.

Regards

Activity icon

Started a new Conversation Bootstrap Modal Open With Record Details

Hi! I have a view which has records for a model. Each reacord is reprsented in boxes and I have a button in each fo them for showing record details in a Boostrap Model.

I'm working with AJAX approach that I have read in some othe questions raised, I'm fetching the click event in JS code and I try to inject the view returned from Controller to the table view.

I'm trying to return the view from Controller for replacing the modal one and I can't make it work, modal is not opening.

Is this the correct aporoach? It's recommended to use View Composer?

Can anyone share his code for a similar exprience?

Regards

Controller code:

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::where('prop_id', $id)->first();
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
}

Button code:

<div class="kt-widget__footer">
	<button type="button"
			class="btn btn-label-primary btn-lg btn-upper openBtn"
			data-toggle="modal"
			data-target="#kt_modal_4_2">
			Open
	</button>
</div>

AJAX code:

$('.openBtn').on('click',function(){
         $('.replace').empty();

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
            type: 'GET',
            url: '/property/details/KWS1389776',
            dataType: 'JSON',

            success: function (data) {
                console.log(data);
                // $('.modal-body').text(data.prop_title);
                 $('.replace').html(data);
                // $('#kt_modal_4_2').modal("show");


            },
        })

        var xhr = $.ajax();
        console.log(xhr);

});

Modal Code

<!--begin::Modal-->
<div class="modal fade replace" id="kt_modal_4_2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" style="display: none;" aria-hidden="true">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Custom</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                </button>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="recipient-name" class="form-control-label">Recipient:</label>
                        <input type="text" class="form-control" id="recipient-name">
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="form-control-label">Message:</label>
                        <textarea class="form-control" id="message-text"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Send message</button>
            </div>
        </div>
    </div>
</div>
<!--end::Modal-->
Mar
21
2 weeks ago
Activity icon

Replied to Laravel ACL Organizations/Groups/Users/Roles Package?

Thanks @gcwilliams I will look at laratrust!

Regards

Activity icon

Replied to Laravel ACL Organizations/Groups/Users/Roles Package?

Thanks @etiennedeschenes ! I have looked at that package and it looks great for user and roles, but as you said, their is no support for groups and organizations. I will keep looking!

Regards

Activity icon

Started a new Conversation Laravel ACL Organizations/Groups/Users/Roles Package?

Hi! I'm trying to find the best package for managing ACL permissions.

The organizational structure needed to manage permissions is:

  1. There will be many Organizations.
  2. There will be many Groups of Users which will belong to each Organization (those Groups will not more than 5 and they will have different users depending the Organization).
  3. There will be many Users which can belong to 1 or more Groups and to 1 or more Organizations.
  4. Users will have 1 or more roles.

The restriction needed is that user's will only access records which belong to his groups/organizations/role

Which one do you recommend?

Regards

Mar
11
3 weeks ago
Activity icon

Started a new Conversation Laravel Vue SPA, Firebase Hosting And Social Login

Hi All!

We want to convert our actual Laravel v7 app into a PWA and host frontend in Firebase and Laravel Backend in Google Cloud VM.

We have to accomplish the following requirements:

  1. Frotend will be moved to VueJS and hosted in firebase
  2. Current login must continue being Social (nowadays we use Socialite package and we restrict in LoginController that only emails from @ourdomain.com can proceed to login)
  3. We want to implement push notifications once PWA is ready

Which are the following recommendations based on requirements?

  1. Do we continue using Socialite package or we move to Laravel Airlock or Firebase Social Authentication?
  2. For Push Notifications, any package for laravel in order to invoke firebase push notifications or do you recommend other approach?

Regards

Feb
10
1 month ago
Activity icon

Replied to Counting Record With HasManyThrough And WithCount

@bobbybouwmann I solved it this way using loadCount

    public function offerdemands()
        {
            return $this->HasMany(Offerdemand::class);
        }

     public function offerdemandsmatchs()
        {
            return $this->hasManyThrough('App\Offerdemand', 'App\Offerdemandsmatchs');
        }

    public function getdata()
    {
        $matchs = User::find(1)->offerdemands;
        $matchs->loadCount('offerdemandsmatchs');
        return response()->json($matchs);
        // dd($matchs);
    }

https://laravel.com/docs/6.x/eloquent-relationships#counting-related-models

Thanks for your help!

Activity icon

Replied to Counting Record With HasManyThrough And WithCount

Hi @bobbybouwmann thanks for your help!

It looks the method concatenated insise withCount is not been recognized:

BadMethodCallException
Call to undefined method App\User::offerdemand.offerdemandsmatchs()
public function getdata()
    {
        $matchs = User::withCount('offerdemand.offerdemandsmatchs')->find(1);
        $offerdemands = $matchs->offerdemand;
        return response()->json($offerdemands);
    }
public function offerdemand()
    {
        return $this->HasMany(Offerdemand::class);
    }

 public function offerdemandsmatchs()
    {
        return $this->hasManyThrough('App\Offerdemand', 'App\Offerdemandsmatchs');
    }

Regards

Activity icon

Started a new Conversation Counting Record With HasManyThrough And WithCount

Hi! I have read many articles about counting records in relationships but i'm having a problem. I have a User model whichs is related to OfferDemand model (1:M) and this one related to OfferDemandMatchs (1:M)

In my user model I have declared the relationships

 public function offerdemands()
     {
         return $this->HasMany(Offerdemand::class);
     }

  public function offerdemandsmatchs()
      {
          return $this->hasManyThrough('App\Offerdemand', 'App\Offerdemandsmatchs');
       }

I want to retrieve each OfferDemannd record with OfferDemandMatchs count nested into each record.

With the following statement I retrieve all OfferDemand records for the user logged in:

  public function getdata()
    {
        $matchs = User::find(1)->offerdemands;
         return response()->json($matchs);
     }

I tried the following statements options but I'm not having the expected result:

$matchs = User::find(1)->offerdemand()->withCount('offerdemandsmatchs');
$matchs->withCount('offerdemandsmatchs')->get();
$matchs = User::find(1)->offerdemand->withCount('offerdemandsmatchs');

Does anyone knows how I can achieve the expected result?

Regards