Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

cmtiffani

Experience

5,070

0 Best Reply Awards

  • Member Since 3 Years Ago
  • 73 Lessons Completed
  • 13 Favorites

27th April, 2017

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

Annoyingly, I think I just figured out the way around this:

App\User::isAdmin() works.

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

Finally got around to this. It worked, sort of.

Doing this still means I have to pass the roles feedback from the request into the view independently in order to access it in my blade file, which seems clunky and means repeating this code everywhere. There has to be a better way to do this....

21st April, 2017

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

I have middleware setup, but I'm not returning the extra info that you are at in the myVar and infos arrays. That may be how I work around this.

Thanks. Will give it a try and see how it goes :)

16th April, 2017

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

You already suggested changing the function to public, so that's not it.

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

They were already uncommented.

My authentication works fine, it's just accessing it through Auth::user()->isAdmin() that doesn't work.

Auth::user() returns the full user model as I'd expect, and User::isAdmin() checks the role status as expected as well.

Any other ideas?

14th April, 2017

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

hmm, tried that and I still get the same error.

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Role;

class User extends Authenticatable
{
    // use SoftDeletes;
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'first_name', 'last_name', 'company', 'email', 'tax_id', 'address', 'city', 'state', 'zip', 'phone','password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function roles()
    {
        return $this->belongsToMany('App\Role');
    }
    /**
     * Find specified user role by id or name
     * @param  [type]  $uid  user_id
     * @param  [type]  $role either name or id
     * @return boolean       [description]
     */
    static function hasRole($uid, $role){
        $user = User::find($uid);

        if(is_numeric($role)){
            foreach ($user->roles as $r) {
                // var_dump($r->id);
                if($r->id == $role){
                    return true;
                }
                return false;
            }
        }else{
            foreach ($user->roles as $r) {
                if($r->name == $role){
                    return true;
                }
                return false;
            }

        }
    }

    static function isAdmin(){
        $user = User::find(Auth::user()->id);

            foreach ($user->roles as $r) {
                if($r->id == 1){
                    return true;
                }
                return false;
            }
    }

}

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

Still gives me an error:

 Call to undefined method Illuminate\Auth\GenericUser::isAdmin()

cmtiffani left a reply on Conditional Menu Items Based On User Role • 7 months ago

I have a few questions about this:

I can't use Auth::user()->role_id as it's a many-to-many relationship, so that column isn't in the user's table. I have a function in my User model for isAdmin() but I'm not sure how to reference this within blade?

I get the error Class 'User' not found with this:

  {{ User::isAdmin() }}

cmtiffani started a new conversation Conditional Menu Items Based On User Role • 7 months ago

I'm getting stuck on something that should be simple.

Using 5.3. I have middleware setup to check if a user is an Admin based on their roles (isAdmin) and I have a function setup for User::hasRole() that can both check if a user has a given role.

I have some conditional menu items that should only appear for admins. how can I check for a role?

21st June, 2016

cmtiffani started a new conversation Changing Config Files Via Automation • 1 year ago

I'm building an app that will need to be able to add /edit additional filesystem settings via the application itself, instead of doing so manually. I want to be able to add new config settings for different disks via a GUI instead of doing it manually.

I found reference to this: https://github.com/daftspunk/laravel-config-writer but it appears to have some issues with Laravel 5.

Is there another / better way to achieve this?

5th February, 2016

cmtiffani left a reply on Repeating Calendar Entries • 1 year ago

@snapey - yeah, that does make it more awkward adding in the people per event component.

I think you're right: use the repeater to create a unique event that can overwrite a single instance. Add a reference field on the unique entry that references the repeat entry. Before you start iterating over the repeat, grab any uniques that also match that reference field. Then when you're iterating over the repeats you just need to check if a unique entry exists for that date iteration and use that data instead. Otherwise, fallback to your default repeat data.

You'll still have to test for stupids - if the client changes the start date from a Sun to a Tue for example, the repeating dates for your unique instances may not match up.

Oh, and as for the 'how long do you let it repeat for' part of the question: I always make them put an end date, even if that's 30 years in the future, but you could probably just as easily leave it open ended, especially if you're not creating an event per recurrence unless it has unique info, which they have to do manually.

cmtiffani left a reply on Repeating Calendar Entries • 1 year ago

I manage several sites for churches and such that have event calendars with repeating events. They want to be able to enter service times for example, and not have to add a new event for every Sunday morning from here till the rapture.

What I currently do is record a single event with 'repeating' properties, so there are settings for the repeat_interval (weekly, monthly, never), repeat_period (every x weeks/months), start_datetime, end_datetime. That's managed through a backend CMS by the client. The front end of the website uses the repeating properties to generate the calendar, typically for a given month, or to suit the view the front end visitor needs to see.

Because this has also come up, if they have an exception to the repeating rule, then it's not repeating. For my sanity repeating = identical. I tell them to stop the repeating before the anomaly, add a one-time event for the oddball instance, and then create another repeating event to carry on after the anomaly.

I know this is a a couple of months old, but maybe it's still useful

3rd February, 2016

cmtiffani left a reply on Passing Variables Through To A Collection Filter() • 1 year ago

I knew it would be simple! Thanks

cmtiffani started a new conversation Passing Variables Through To A Collection Filter() • 1 year ago

I'm loosing the plot on something that should be simple.

I have a collection that I want to filter. Take the following example:

// Create an array of fruits
$array = ["banana", "apple", "orange"];

// Transform the array into a Collection object
$collection = new Illuminate\Support\Collection($array);

// We don't like banana's anymore, so we're going to filter them out
$no_bananas = $collection->filter(function($element) {
    if ($element != "banana") return true;
});

// Dump out our array now, and we'll see the banana's are gone
dd($no_bananas);

Works great assuming I only ever want to filter by 'banana'. What if I want to use a variable within the filter. How do I do that?

// Create an array of fruits
$array = ["banana", "apple", "orange"];
$filterby = 'apple';

// Transform the array into a Collection object
$collection = new Illuminate\Support\Collection($array);

// We don't like banana's anymore, so we're going to filter them out
$filtered = $collection->filter(function($element) {
    if ($element != $filterby) return true;
});

// Dump out our array now, and we'll see the banana's are gone
dd($filtered);

The above won't work because $filterby isn't available in the filter() function. How would I make it available?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.