Ask, reply and learn. Join the community of Akaunting.
Hi
New to akaunting development (well versed in Laravel). I have created a new module, then I made a controller for it. To load a view, I changed the default route to load "MyController@index" like so:
Route::admin('admissions', function () {
Route::get('/', 'MyController@index')->name('index');
});
Now, whenever I load the page, I get 403 error. Even though I've updated the permissions in the "FinishInstallation.php" file to:
protected function updatePermissions()
{
// c=create, r=read, u=update, d=delete
$this->attachPermissionsToAdminRoles([
// $this->alias . '-main' => 'c,r,u,d',
$this->alias . '-mycontroller' => 'c,r,u,d',
]);
}
Am I missing anything obvious here?
Got it to work by manually adding the middleware in the controller like so:
$this->middleware('permission:create-students')->only('create', 'read', 'update', 'delete');
The Listener method is not working for me.
Funny thing is, nothing is registered in the permissions section when I visit the page. And now, after commenting the middlewares, it's working. I have no idea what's going on with my module.
Others with likely the same problem:
https://akaunting.com/forum/discussion/development/create-route-with-controller-method
https://akaunting.com/forum/discussion/development/add-new-menu-navbar
https://akaunting.com/forum/discussion/development/i-want-to-create-custom-controller-and-view-and-its-shows
https://akaunting.com/forum/discussion/development/module-routing-403
I've figured out the problem, but not the solution yet. The "FinishInstallation" Listener is called on the "Installed" event which is only fired when you install the module (the first time). Now, during development, where you would have to add and subtract permissions now and then, what should we do? No idea.
However, what if we uninstall and install the module back again? Bad luck, just by uninstalling a module, you delete it from you directory!
Akaunting is attractive and great, but the community platform is relatively small and growing, and the documentation needs to be a lot more starter friendly and literally walk through all the challenges a starter would face...
[SOLVED!]
After quite some playing around, figured out that built-in modules seed the permissions into the database. So did the same for my module.
My module's seeder:
class MyModuleDatabaseSeeder extends Seeder
{
use Permissions;
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->permissionsSeeder();
Model::reguard();
}
// Seed admin permissions
public function permissionsSeeder() {
$this->attachPermissionsToAdminRoles([
'my-module-blog' => 'c,r,u,d'
]);
}
}
And then ran: "php artisan module:seed my-module"
So every time I add controllers or any thing (for that matter of fact) which requires permission, I'd have to come and do this.
Hope this is included in the documentation (or a better way) for beginners to quickly get a grasp of how to deal with Akaunting modules.
Showing 1 to 5 of 5 discussions