lbottoni

lbottoni

Member Since 3 Years Ago

Experience Points
650
Total
Experience

4,350 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
0
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.

Level 1
650 XP
Oct
10
1 week ago
Activity icon

Replied to Policy Never Called

yes @nakov, but now i want investigate and I want to correct this error in my logic (or knowledge of laravel)

very thanks @nakov for your help

Activity icon

Replied to Policy Never Called

Yes Nakov, was my problem

//      $SoccerGate=new SoccerGate();
//      Gate::define('allow-env', 'App\MySoccer\Classes\[email protected]');
//      Gate::before([$SoccerGate,"before"]);

but the question is, why this custom gate noise the policy system!?

<?php

namespace App\MySoccer\Classes;


use App\User;

class SoccerGate
    {
    public function allowEnv(User $user, $env = null)
        {

            $valueUser = Utils::getvaluepermission($user->user_type);
            $valueRequest = Utils::getvaluepermission($env);

            return (Utils::getvaluepermission($user->user_type) >= Utils::getvaluepermission($env));
        }

    public  function before(User $user)
        {
            if ($user->is_root())
                {
                return true;
                }
        }
    }
Activity icon

Replied to Policy Never Called

makes no sense to me either! yes i'm arrive in controller, my xdebug work and the the delete remove correctly the federation model

Federation {#342
  #table: "federations"
  #fillable: array:4 [
    0 => "user_id"
    1 => "name"
    2 => "created_at"
    3 => "updated_at"
  ]
  #dates: array:2 [
    0 => "deleted_at"
    1 => "deleted_at"
  ]
  #connection: "mysql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:6 [
    "id" => 6
    "name" => "fedtest1"
    "user_id" => 8
    "created_at" => "2019-10-09 10:30:07"
    "updated_at" => "2019-10-10 06:58:34"
    "deleted_at" => null
  ]
  #original: array:6 [
    "id" => 6
    "name" => "fedtest1"
    "user_id" => 8
    "created_at" => "2019-10-09 10:30:07"
    "updated_at" => "2019-10-10 06:58:34"
    "deleted_at" => null
  ]
  #changes: []
  #casts: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [
    0 => "*"
  ]
  #forceDeleting: false
}
Activity icon

Replied to Policy Never Called

route with "web" middleware or no, not work

Route::group([
    'prefix'     => "admin",
    'middleware' => ["clearcache","auth"],
    'namespace'  => 'App\Http\Controllers'
], function () { // custom admin routes
    // --------------------------------------------------------------------------
    //                      ROUTE PANEL USER_TYPE
    // --------------------------------------------------------------------------
    Route::resource('/dashboard/crud/federations', 'Admin\FederationController');
    //Rotta per indicare in sessione quale panel si sta lavorando admin|team|player
    Route::get('/dashboard/{panel_type?}', '[email protected]')->where('panel_type', '(admin|team|player|root)')->middleware("usertype")->name("admin_user_type");
    Route::get('/dashboard', '[email protected]')->name("dashboard");

}); 

laravel version is 5.8 it's very strange that policy methods are not never called :|

Activity icon

Replied to Policy Never Called

FederationController.php

namespace App\Http\Controllers\Admin;

use App\Models\Database\Federation;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
//use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use App\MySoccer\Classes\MySoccerResponse;

class FederationController extends Controller
    {
//  use AuthenticatesUsers;

    //  protected $redirectTo = '/public/login';
    public function __construct()
        {
//          $this->authorizeResource(Federation::class);
        }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
        {
            $user = Auth::user();

            return view('admin.federation',
                ["name" => "federation",
                 "federations" => $federations
                ]);
        }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Federation $federation, Request $request)
        {
            //
            dd([$request->expectsJson(),
                $request,
                $this
            ]);
        }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
        {
            //
            dd($this);
        }

    /**
     * Display the specified resource.
     *
     * @param \App\Models\Database\Federation $federation
     * @return \Illuminate\Http\Response
     */
    public function show(Federation $federation)
        {
            //
            dd($this);
        }

    /**
     * Show the form for editing the specified resource.
     *
     * @param \App\Models\Database\Federation $federation
     * @return \Illuminate\Http\Response
     */
    public function edit(Federation $federation)
        {
            //
            dd($this);
        }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request        $request
     * @param \App\Models\Database\Federation $federation
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Federation $federation)
        {
            //
            dd($this);
        }

    /**
     * Remove the specified resource from storage.
     *
     * @param \App\Models\Database\Federation $federation
     * @return \Illuminate\Http\Response
     */
    public function destroy(Federation $federation, Request $request)
        {
            $this->authorize('delete', $federation);//with ore without not call the policy!
            return $federation->delete()?MyResponse::success():MyResponse::error("oh no!!!!this is a fake message from remote server");
        }
    }

AuthServiceProvider.php

<?php

namespace App\Providers;

use App\MyApp\Classes\Utils;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use App\MyApp\Classes\SoccerGate;
use App\Policies\FederationPolicy;
use App\Models\Database\Federation;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
        Federation::class => FederationPolicy::class
    ];

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

        //definisco se lo user di lavoro è di un tipo (es:player) che può non può accedere
        //all'ambiente di lavoro
        $SoccerGate=new SoccerGate();
        Gate::define('allow-env', 'App\MyApp\Classes\[email protected]');
        Gate::before([$SoccerGate,"before"]);

    }
}

FederationPolicy.php

<?php

namespace App\Policies;

use App\User;
use App\Models\Database\Federation;
use Illuminate\Auth\Access\HandlesAuthorization;

class FederationPolicy
{
    use HandlesAuthorization;

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

    /**
     * Determine whether the user can create federations.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        //
        $avatar=$user->getAvatar();
    }

    /**
     * Determine whether the user can update the federation.
     *
     * @param  \App\User  $user
     * @param  \App\Models\Database\Federation  $federation
     * @return mixed
     */
    public function update(User $user, Federation $federation)
    {
        //
        dd();
    }

    /**
     * Determine whether the user can delete the federation.
     *
     * @param  \App\User  $user
     * @param  \App\Models\Database\Federation  $federation
     * @return mixed
     */
    public function delete(User $user, Federation $federation)
    {
        $avatar=$user->getAvatar();
        $id=$federation->id;
        return false;
        //
    }

    /**
     * Determine whether the user can restore the federation.
     *
     * @param  \App\User  $user
     * @param  \App\Models\Database\Federation  $federation
     * @return mixed
     */
    public function restore(User $user, Federation $federation)
    {
        //
        dd();
    }

    /**
     * Determine whether the user can permanently delete the federation.
     *
     * @param  \App\User  $user
     * @param  \App\Models\Database\Federation  $federation
     * @return mixed
     */
    public function forceDelete(User $user, Federation $federation)
    {
        //
        dd();
    }
}

ROUTES

|        | GET|HEAD                               | admin/dashboard/crud/federations                   | federations.index   | App\Http\Controllers\Admin\[email protected]           | web,clearcache,auth                                           |
|        | POST                                   | admin/dashboard/crud/federations                   | federations.store   | App\Http\Controllers\Admin\[email protected]           | web,clearcache,auth,can:create,App\Models\Database\Federation |
|        | GET|HEAD                               | admin/dashboard/crud/federations/create            | federations.create  | App\Http\Controllers\Admin\[email protected]          | web,clearcache,auth,can:create,App\Models\Database\Federation |
|        | DELETE                                 | admin/dashboard/crud/federations/{federation}      | federations.destroy | App\Http\Controllers\Admin\[email protected]         | web,clearcache,auth,can:delete,delete                         |
|        | PUT|PATCH                              | admin/dashboard/crud/federations/{federation}      | federations.update  | App\Http\Controllers\Admin\[email protected]          | web,clearcache,auth,can:update,delete                         |
|        | GET|HEAD                               | admin/dashboard/crud/federations/{federation}      | federations.show    | App\Http\Controllers\Admin\[email protected]            | web,clearcache,auth,can:view,delete                           |
|        | GET|HEAD                               | admin/dashboard/crud/federations/{federation}/edit | federations.edit    | App\Http\Controllers\Admin\[email protected]            | web,clearcache,auth,can:update,delete

Activity icon

Replied to Policy Never Called

it's only a line for my memories 'App\Model' => 'App\Policies\ModelPolicy'

Oct
09
1 week ago
Activity icon

Replied to Policy Never Called

Model is imported :(

use App\Models\Database\Federation;

class AuthServiceProvider extends ServiceProvider
{

and

    public function destroy(Federation $federation, Request $request)
        {
            $this->authorize('delete', $federation);
            return $federation->delete()

but the policy delete method is never called :*(, i can not understand where is the error

Activity icon

Started a new Conversation Policy Never Called

Hi all, i a new in laravel and i want try use the Model policy

i have create Model, ModelPolicy and Route resource. after i have registred the join class=>policy in in AuthServiceProvider.

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
        Federation::class => FederationPolicy::class
    ];

in FederationPolicy.php

class FederationPolicy
{
    use HandlesAuthorization;
    public function delete(User $user, Federation $federation)
    {
        //i return false only for test, here i have a stop with xdebug
        return false;
        //
    }

in FederationController .php

class FederationController extends Controller
    {
    use AuthenticatesUsers;

    //  protected $redirectTo = '/public/login';
    public function __construct()
        {
            //$this->authorizeResource(Federation::class,"delete");//not work
            //$this->authorizeResource(Federation::class,"destroy");//not work
            //$this->authorizeResource(Federation::class);//not work

        }
    public function destroy(Federation $federation, Request $request)
        {
            $federation->delete()

why the delete() method never pass inside delete method of FederationPolicy ?where is my error?

the route is controlled by Route::resource('/dashboard/crud/federations', 'Admin\FederationController');