jediping

jediping

Member Since 3 Years Ago

Experience Points 4,620
Experience
Level
Lessons Completed 39
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

06 Dec
1 week ago

jediping started a new conversation Testing Passport Logout -- Is It Possible?

I'm trying to figure out how to test my Passport-driven logout function, which looks like this: ```public function logout() { $accessToken = auth()->user()->token();

    $refreshToken = DB::table('oauth_refresh_tokens')
        ->where('access_token_id', $accessToken->id)
        ->update([
            'revoked' => true
        ]);

    $accessToken->revoke();

    return response()->json(['status' => 200]);
}```

I am using the Passport actingAs helper in setting up the response. Passport::actingAs( $user, ['read write'] ); $response = $this->post('/logout') ->assertStatus(200); The test fails, as the code gives a 500 error, as auth()->user()->token() is ... empty-ish? $accessToken->id is 0, for example, which it shouldn't be, which means the code fails.

What I'm not sure about is if this is expected behavior because of how Passport's actingAs helper works and I can't actually test the logout function, or if there's something wrong with my logout function. Halp!

23 Jan
10 months ago

jediping started a new conversation Can I Get This Cookie In Middleware Right Away?

I’ve got a single sign-on emulator that does a redirect and sets a cookie. I’ve got a middleware (GenerateMenus) that checks the cookie and loads the auth information from the SSO emulator, rather than the default auth stuff, if that cookie is set. It works fine except right after clicking the login button.

The GenerateMenus middleware is called before the cookie appears, so it thinks the user isn’t logged in and gives the wrong display. Once the page loads, a refresh or form submit will give the right menu.

So, I think the cookie is being set after the middleware runs. Any looking at cookies I do before then doesn't show the new cookie. Any ideas on how to find this cookie before it becomes a cookie? scratches head

Setting the cookie:

                ->to(RegistrationController::GetMemberRoute($member_id))
                ->withCookies([SsoEmulator::BakeCookie($member_id, $member_data)]);```

The cookie check that fails:
```!empty(\Cookie::get(config('COOKIENAME')));```


My web middleware group:
```        'web' => [            // Utilize custom cookie encryter.
            \App\Http\Middleware\SpecialEncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\SetLocalization::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\GenerateMenus::class,
        ],```
24 Aug
1 year ago

jediping left a reply on Interactive Dropdowns

It appears so, yes. Finally learned how to send down a prop but then be able to change it. I think there's still probably a lot of clean-up I can do here.

HTML:

<regions-select name="region" class="form-control" :regions="regions" :selecttext="{{json_encode(trans('app.region_select'))}}"></regions-select>
<districts-select name="district" class="form-control" :districts="districts" :selecttext="{{json_encode(trans('app.district_select'))}}"></districts-select>

Script

    var events = new Vue();

    Vue.component('select-item', {
        props: ['name', 'selecttext', 'items', 'item', 'tofire'],
        template: `
            <select name="name" v-model="selectedItem">
                <option value="null">@{{selecttext}}</option>
                <option v-for="(item, index) in items" :value="index">
                    @{{item}}
                </option>
            </select>
        `,
        data() {
            return {
                selectedItem: this.item
            }
        },
        watch: {
            selectedItem: function(val) {
                this.$emit('item-updated', {val});
            }
        }
    });

    

    Vue.component('regions-select', {
        props: ['name', 'regions', 'selecttext'],
        template: `
            <select-item v-model="region" :name="name" :selecttext="selecttext" :items="regions" :item="region" v-on:item-updated="regionUpdated"></select-item>
        `,
        data() {
            return {
                region: {!! json_encode(isset($rule) ? $rule->region_id : null) !!}
            }
        },
        methods: {
            regionUpdated(event) {
                this.region = event.val;
            }
        },
        watch: {
            region: function(val) {
                events.$emit('region-updated', {val});
            }
        }
    });

    Vue.component('districts-select', {
        props: ['name', 'districts', 'selecttext'],
        template: `
            <select-item v-model="district" :name="name" :selecttext="selecttext" :items="districts" :item="district" v-on:item-updated="districtUpdated"></select-item>
        `,
        data() {
            return {
                district: {!! json_encode(isset($rule) ? $rule->district_id : null) !!},
            }
        },
        methods: {
            districtUpdated(event) {
                this.district = event.val;
            }
        },
        watch: {
            district: function(val) {
                events.$emit('district-updated', {val});
            }
        }
    });

    

    var app = new Vue({
        el: '#app',
        data: {
            regions: {!! json_encode($regions) !!},
            rule: {!! json_encode(isset($rule) ? $rule : null) !!},
            site: {!! json_encode($site) !!},
            districtShow: false,
            districts: [],
            storeShow: false,
            stores: [],
            categories: [],
        },
        mounted() {
            if(this.rule != null) {
                this.region_id = this.rule.region_id;
                if(this.region_id != null) {
                    this.updateDistricts(this.region_id);
                }
                this.district_id = this.rule.district_id;
                if(this.district_id != null) {
                    this.updateStores(this.district_id);
                }
                this.category_id = this.rule.category_id;
            }
            events.$on('region-updated', function(value) {
                app.updateDistricts(value.val);
            });
            events.$on('district-updated', function(value) {
                app.updateStores(value.val);
            });

        },
        methods: {
            updateDistricts(region_id) {
                this.districtShow = true;
                axios.get('/admin/ajax/getDistricts/' + this.site + '/' + region_id).then(response => this.districts = response.data);
                this.stores = [];
                this.storeShow = false;
            },
            updateStores(district_id) {
                this.storeShow = true;
                axios.get('/admin/ajax/getStores/' + this.site + '/' + district_id).then(response => this.stores = response.data);
            },
            updateSubcategories(category_id) {
                alert(category_id);
            }
        }
    });

jediping left a reply on Pivot Table As Main Focus

I think there's no reason not to also have a positions relationship on team. That way, you can replace

$positions = Position::where('team_id', $team->id)->orderBy('slot', 'asc')->get()->keyBy('slot');

with

$positions = $team->positions->sortBy('slot')->keyBy('slot');

But for the loop, I think that's probably the best way to do it. You could save a bit of space by putting just the second and third TDs in the if statement, since they first one is always the same, but otherwise this seems solid to me.

jediping started a new conversation Interactive Dropdowns

I've built my first Vue thing, which is three dropdowns, regions, districts, and stores. When you select a region, the region's districts show up. When you select the district, the stores show up. There may be a default value for any of these fields. I'd appreciate any thoughts on how I could improve this.

A couple of things I'd appreciate suggestions on:

  • I feel like I'm re-using a lot of code between the different selects. I've got to build a couple more sets of interactive dropdowns, and I know copy-paste is NOT the best way to go about it!
  • I'd like to figure out a better way to get any default values, in order to make this reusable. For example, instead of a Rule object, the value might be in a seachterms array.
                        <div class="col-xs-4">
                            {!! Form::label('region_select',  trans("app.region_select")) !!}
                            <regions-select name="region" class="form-control" :regions="regions"></regions-select>
                        </div>
                        <div class="col-xs-4" v-if="districtShow">
                            {!! Form::label('district_select',  trans("app.district_select")) !!}
                            <districts-select name="district" class="form-control" :districts="districts"></districts-select>
                        </div>
                        <div class="col-xs-4" v-if="storeShow">
                            {!! Form::label('store_select',  trans("app.store_select")) !!}
                            <stores-select name="store" class="form-control" :stores="stores"></stores-select>
                        </div>
                    </div>```

```var events = new Vue();

    Vue.component('regions-select', {
        props: ['regions'],
        template: `
            <select name="name" v-model="region">
                <option value="null">{{trans('app.region_select')}}</option>
                <option v-for="(region, index) in regions" :value="index">
                    @{{region}}
                </option>
            </select>
        `,
        data() {
            return {
                region: {!! json_encode(isset($rule) ? $rule->region_id : null) !!}
            }
        },
        watch: {
            region: function(val) {
                events.$emit('region-updated', {val});
            }
        }
    });

    Vue.component('districts-select', {
        props: ['districts'],
        template: `
            <select name="name" v-model="district">
                <option value="null">{{trans('app.district_select')}}</option>
                <option v-for="(district, index) in districts" :value="index">
                    @{{district}}
                </option>
            </select>
        `,
        data() {
            return {
                district: {!! json_encode(isset($rule) ? $rule->district_id : null) !!},
            }
        },
        watch: {
            district: function(val) {
                events.$emit('district-updated', {val});
            }
        }
    });

    Vue.component('stores-select', {
        props: ['stores'],
        template: `
            <select name="name" v-model="store">
                <option value="null">{{trans('app.store_select')}}</option>
                <option v-for="(store, index) in stores" :value="index">
                    @{{store}}
                </option>
            </select>
        `,
        data() {
            return {
                store: {!! json_encode(isset($rule) ? $rule->store_id : null) !!},
            }
        }
    });


    var app = new Vue({
        el: '#app',
        data: {
            regions: {!! json_encode($regions) !!},
            rule: {!! json_encode(isset($rule) ? $rule : null) !!},
            site: {!! json_encode($site) !!},
            districtShow: false,
            districts: [],
            storeShow: false,
            stores: [],
        },
        mounted() {
            if(this.rule != null) {
                this.region_id = this.rule.region_id;
                if(this.region_id != null) {
                    this.updateDistricts(this.region_id);
                }
                this.district_id = this.rule.district_id;
                if(this.district_id != null) {
                    this.updateStores(this.district_id);
                }
            }
            events.$on('region-updated', function(value) {
                app.updateDistricts(value.val);
            });
            events.$on('district-updated', function(value) {
                app.updateStores(value.val);
            });
        },
        methods: {
            updateDistricts(region_id) {
                this.districtShow = true;
                axios.get('/admin/ajax/getDistricts/' + this.site + '/' + region_id).then(response => this.districts = response.data);
                this.stores = [];
                this.storeShow = false;
            },
            updateStores(district_id) {
                this.storeShow = true;
                axios.get('/admin/ajax/getStores/' + this.site + '/' + district_id).then(response => this.stores = response.data);
            }
        }
    });```
03 Aug
3 years ago

jediping left a reply on Using A Function From Another Controller

A much-belated thanks to everybody for your help. I ended up going a different route, by using the event firing/listening thing. I am pretty sure I'll need to add more actions as a user is created, so figuring that stuff out will be helpful as I keep working on this app. Thanks again!

15 Jul
3 years ago

jediping left a reply on Using A Function From Another Controller

@pmall, any recommended reading on using a service class? I've not done that before.

@uxweb, is that going to create problems with a Laravel update in the future? (Did I mention I'm a noob?) :)

jediping started a new conversation Using A Function From Another Controller

I've got several places in my app where one controller needs to access a method in another controller. I tried something like this:

ToysController.php

public function new_user_toy(User $user){
[trim]
        //Make sure the toy knows how to make itself and one other pattern
        ToyPattern::store($toy->id, $toy_pattern->id);
        ToyPattern::store($toy->id, $known_pattern->id);
    }

It doesn't work, and from what I've read on the issues, it shouldn't, because I shouldn't be having controllers talk to each other. (Plus I think that actually calls the model, not the controller.) Unfortunately, I haven't been able to find any resources on how to implement something like this correctly in the MVC framework. I read a bit that suggested going through the model, but didn't really provide a good example on how that would work.

Some things I'm trying to do: When a new user is created, assign them a toy. (Many-to-many relationship between toys and users.) When a toy is created, assign it two known patterns. (One-to-many relationship between toys and known patterns.)

I'm pretty new to Laravel and MVC, so even some basic guidance here would be great.

11 Jun
3 years ago

jediping left a reply on Adding An Object To A Collection

As I suspected, there WAS a much easier way to do this. I used Query Builder, a group by statement, and some fun sums and came up with this:

use Illuminate\Database\Eloquent\Collection;

[snip]

    public function CTRindex(Collection $collection){
        //Select the data, doing the sums as we go
        $funding_sources=DB::table('funding_sources')
            ->select('fiscal_year',DB::raw('sum(funded) as funded, sum(spent) as spent, sum(obligated) as obligated, sum(impact_fee) as impact_fee, sum(funded - spent - obligated - impact_fee) as available_funds'))
            ->groupBy('fiscal_year')
            ->get();
        //Turn the results into a collection
        $funding_sources=$collection->make($funding_sources);
        $title="CTR Summary";
        $summary_type="CTR";
        return view('funding_sources.index', compact('funding_sources', 'title','summary_type'));
    }

Using the Illuminate...Collection and the $collection->make converted the query builder results into a collection, so I could then use most of the templates I had already built. I had to make a few tweaks, but it was a lot less painful than the road I was going down. :)

jediping started a new conversation Adding An Object To A Collection

Relative newbie to Laravel. (And programming in general.) :)

I have a collection called FundingSources. Each funding source has a fiscal year and a type of funding. There may be more than one object in the collection with the same fiscal year (but a different type_of_funding), but there may be only one. The start of the var_dump for one of the funding sources looks like:

 55 => 
    object(App\FundingSource)[203]
      protected 'guarded' => 
        array (size=0)
          empty
      protected 'connection' => null
      protected 'table' => null
      protected 'primaryKey' => string 'id' (length=2)
      protected 'perPage' => int 15
      public 'incrementing' => boolean true
      public 'timestamps' => boolean true
      protected 'attributes' => 
        array (size=10)
          'id' => int 2
          'fiscal_year' => string '10' (length=2)
          'type_of_funding' => string 'impact' (length=6)
          'slug' => string 'fy10-impact' (length=11)
          'funded' => string '4140348.00' (length=10)
          'spent' => string '3387850.00' (length=10)
          'obligated' => string '478337.00' (length=9)
          'impact_fee' => string '213554.00' (length=9)
          'created_at' => string '2015-06-09 19:14:35' (length=19)
          'updated_at' => string '2015-06-09 19:14:35' (length=19)
      protected 'original' => 
        array (size=10)
          'id' => int 2
          'fiscal_year' => string '10' (length=2)
          'type_of_funding' => string 'impact' (length=6)
          'slug' => string 'fy10-impact' (length=11)
          'funded' => string '4140348.00' (length=10)
          'spent' => string '3387850.00' (length=10)
          'obligated' => string '478337.00' (length=9)
          'impact_fee' => string '213554.00' (length=9)
          'created_at' => string '2015-06-09 19:14:35' (length=19)
          'updated_at' => string '2015-06-09 19:14:35' (length=19)
   etc....

When there are multiple objects with the same fiscal year, I need to total up the various funded, spent, obligated, and impact_fee amounts. I'm struggling to find a way to do this easily, so what I've come up with so far is this:

$funding_sources = FundingSource::all();
        //Get the possible fiscal years
        $this->fiscal_years = FundingSource::distinct()->lists('fiscal_year');

        //Add a "totals" attribute for each fiscal year to the collection
        foreach($this->fiscal_years as $fiscal_year){
            $this->new_item=[SOMETHING HERE???];
            $this->new_item->fiscal_year = $fiscal_year;
            $this->new_item->type_of_funding = 'total';
            $this->new_item->slug = $fiscal_year.'_total';
            $this->new_item->funded = 0;
            $this->new_item->spent = 0;
            $this->new_item->obligated = 0;
            $this->new_item->impact_fee = 0;
            $this->new_item->total=0;
            $funding_sources->splice(null,null,$this->new_item);
        }

I'm not sure what to put in place of SOMETHING HERE that would mean that, when I splice on $this->new_item, it is an object like the other parts of the collection. If I can do that, I can more easily re-use the same view templates as when I don't do this summing. (I need to have both views.) What should I put in the SOMETHING HERE space? Or is there another way to get this object? I've poked around with variations of "new" and "newCollection," but I can't find the correct incantation. :)

Also, my plan would be to next go through the collection, using filters to get each sub-set of funding by fiscal years and adding them to the "funded," "spent," etc items in this new object. If there's an easier way to do all this, I wouldn't mind being pointed in the right direction. I feel like there SHOULD be an easier way to do this, but I don't yet know the right terms to find and implement it.

Thanks in advance!

08 Jun
3 years ago

jediping left a reply on Onsubmit Possible?

Ah, that is true, I don't have a function. That text works, I just had to move it in one set of parentheses.... /hides under the desk/

{!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('countries.destroy', $country->slug),'onsubmit' => 'confirm("Are you sure?")')) !!}
                    <a href="{{ route('countries.show', $country->slug) }}">{{ $country->country }}</a> - {{ $country->region }}
                    (
                    {!! link_to_route('countries.edit', 'Edit', array($country->slug), array('class' => 'btn btn-info')) !!},
                    {!! Form::submit('Delete', array('class' => 'btn btn-danger')) !!}
                    )
                    {!! Form::close() !!}

That works. Thanks! :)

jediping started a new conversation Onsubmit Possible?

Building on what I learned in this tutorial series (https://www.flynsarmy.com/2015/02/creating-a-basic-todo-application-in-laravel-5-part-1/), I have created an index of my countries, with the option to delete a country. That all works fine, but I'd love to be able to add a confirmation dialog to the delete option.

I did a lot of googling and forum-searching, and I found a thread (http://stackoverflow.com/questions/26625584/confirm-delete-with-laravel-form) that seems to imply I can just add 'onsubmit' => 'return ConfirmDelete()' to the Form::open array, like this:

{!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('countries.destroy', $country->slug)),'onsubmit' => 'return ConfirmDelete()') !!} {{ $country->country }} - {{ $country->region }} ( {!! link_to_route('countries.edit', 'Edit', array($country->slug), array('class' => 'btn btn-info')) !!}, {!! Form::submit('Delete', array('class' => 'btn btn-danger')) !!} ) {!! Form::close() !!}

However, trying that gives me "syntax error, unexpected '=>' (T_DOUBLE_ARROW)." So, I assume I can't do that. Being new to Laravel, I'm not sure if I'm just not using the right search terms or what. Any help on how to create a confirmation dialog on this delete form would be appreciated!