jesse_orange_newable

jesse_orange_newable

Member Since 7 Months Ago

Experience Points 1,920
Experience Level 1

3,080 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 17
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

09 Sep
1 week ago

jesse_orange_newable left a reply on All Policies Return A 403

Using your advice about breakpoints I was able to see that my AuthServiceProvider was actually missing use App\Article;, so fundamentally the application didn't know how to resolve the class. Instead of dying it just failed every Gate check.

Thanks for all your advice on the subject.

jesse_orange_newable left a reply on All Policies Return A 403

I have a secondary gate, which returns this:


success
array:4 [▼
  "ability" => "create articles"
  "result" => true
  "user" => "jesseo"
  "arguments" => "[]"
]

Then in my Policy I have this:


    /**
     * Determine whether the user can create articles.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        if ($user->can('create articles')) {
            return true;
        }
    }

I know that the user can create articles, so how is it resolving to false?

jesse_orange_newable left a reply on All Policies Return A 403

In my User model I am defining the following:


 /**
     * Table to use
     */
    protected $table = 'users';

    /**
     * Set the Primary Key
     *
     * @var string
     */
    protected $primaryKey = 'username';

jesse_orange_newable left a reply on All Policies Return A 403

Sorry but this made no difference.

jesse_orange_newable left a reply on All Policies Return A 403

Yes, and my policy looks like this:


<?php

namespace App\Policies;

use App\User;
use App\Article;
use Illuminate\Auth\Access\HandlesAuthorization;

class ArticlePolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view the article.
     *
     * @param  \App\User  $user
     * @param  \App\Article  $article
     * @return mixed
     */
    public function view(User $user, Article $article)
    {
        //
    }

    /**
     * Determine whether the user can create articles.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        return true;
    }

    /**
     * Determine whether the user can update the article.
     *
     * @param  \App\User  $user
     * @param  \App\Article  $article
     * @return mixed
     */
    public function update(User $user, Article $article)
    {
        return true;
    }

    /**
     * Determine whether the user can delete the article.
     *
     * @param  \App\User  $user
     * @param  \App\Article  $article
     * @return mixed
     */
    public function delete(User $user, Article $article)
    {
        return true;
    }

    /**
     * Determine whether the user can restore the article.
     *
     * @param  \App\User  $user
     * @param  \App\Article  $article
     * @return mixed
     */
    public function restore(User $user, Article $article)
    {
        return true;
    }

    /**
     * Determine whether the user can permanently delete the article.
     *
     * @param  \App\User  $user
     * @param  \App\Article  $article
     * @return mixed
     */
    public function forceDelete(User $user, Article $article)
    {
        return true;
    }
}

Then in my ArticleController I have methods like so:


 /**
     * Show the form for creating a new resource.
     *
     * @param  Request  $request
     * @return Response
     * @throws \Illuminate\Auth\Access\AuthorizationException
     */
    public function create()
    {
        $this->authorize('create', Article::class);

        $categories = $this->categories;

        return view('editable.news.create', compact('categories'));
    }

Then in my AuthServiceProvider I have this:


<?php

namespace App\Providers;

use App\Joiner;
use App\ExpensePersonal;
use App\ExpenseMileage;
use App\CreditStatement;
use App\CreditTransaction;
use App\ExpenseFile;
use App\Policies\ArticlePolicy;
use App\Policies\ExpensePersonalPolicy;
use App\Policies\ExpenseMileagePolicy;
use App\Policies\CreditStatementPolicy;
use App\Policies\CreditTransactionPolicy;
use App\Policies\JoinerPolicy;
use App\Policies\ExpenseFilePolicy;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        Article::class => ArticlePolicy::class,
        Joiner::class => JoinerPolicy::class,
        ExpensePersonal::class => ExpensePersonalPolicy::class,
        ExpenseMileage::class => ExpenseMileagePolicy::class,
        CreditStatement::class => CreditStatementPolicy::class,
        CreditTransaction::class => CreditTransactionPolicy::class,
        ExpenseFile::class => ExpenseFilePolicy::class
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        // Ensure admin users bypass gate checksv
        Gate::before(function ($user) {
            return $user->hasRole('admin') ? true : null;
        });
    }
}


The actual Gate returns the following:


array:4 [▼
  "ability" => "update"
  "result" => false
  "user" => "jesseo"
  "arguments" => "[0 => Object(App\Article)]"
]

jesse_orange_newable left a reply on All Policies Return A 403

I'll try to scale down and then I'll post again.

07 Sep
1 week ago

jesse_orange_newable left a reply on All Policies Return A 403

In the AuthServiceProvider I have Article::class => ArticlePolicy::class in the policies array, and have included the appropriate use statements.

It's very peculiar because it doesn't feel like the policy is triggering as even if you abort with a custom message you just get the standard "This action is unauthorized" .

In my ArticleController I use the helper in this way $this->authorize('create', Article::class); in a method with a stub of public function create()

jesse_orange_newable started a new conversation All Policies Return A 403

I went back to a Laravel 5.6 application to add Policies and it always returns a 403 response, even when explicitly returning true. Has anyone else experienced this?