Support the ongoing development of Laravel.io →
Authentication Security
Last updated 1 year ago.
0

I'm having the same problem. What version of Laravel are you running and on what box and PHP version? I myself am running on a homestead-7/PHP-7 set-up. I think with Laravel v5.1.24. Even if I "return true;" from the Policy, it does not work.

Last updated 8 years ago.
0

I am running Apache 2.4 on Windows with PHP Version 5.6.15, mycrypt enabled and MySQL, and it's Laravel 5.1.23. I tried another tutorial where I got the auth()->user->id and that didn't work either so I'm thinking it's to do with the auth/user object. Unfortunately I am brand new to laravel so don't know how to prove/disprove this... Thinking of going back to Symfony2 but heard Laravel was better + easier to use... Not for me so far I'm afraid! Would love to be proven wrong though!

0

I can get this to work:

AuthServiceProvider.php:

    public function boot(GateContract $gate)
    {
		$this->registerPolicies($gate);
                $gate->define('delete-project', function($user, $project) {
			return $user->id == $project->user_id;
		});
		
    }

ProjectController.php:

    public function destroy(Request $request, Project $project)
    {
		//$this->authorize('destroy', $project);
		//$project->delete();
		
		if(Gate::allows('delete-project', $project)) {
			$project->delete();
		} else {
			abort(403);
		}
		
                return redirect('/projects');
    }

But the $this->authorize() and use of policies doesn't work...

Last updated 8 years ago.
0

Okay I got the policies working. I had to add at the top of AuthServiceProvider.php these lines:

use App\Project;
use App\Policies\ProjectPolicy;

...
public function boot(GateContract $gate)
{
        //parent::registerPolicies($gate);		
        $this->registerPolicies($gate);
}
Last updated 8 years ago.
0

Ah, good find! Works here also now. I see they do do it here: http://laravel.com/docs/5.1/authorization#creating-policies Maybe someone should edit the tutorials to explicitly point it out..

Last updated 8 years ago.
0

Yep I too would appreciate slightly expanded tutorials.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.