Laravel Backpack Permissions From Setup - php

I am currently using the PermissionManager package for Laravel-Backpack, and I see instructions on how to add permissions through the UI. I need to add roles and permissions from a script or setup (DB Migration maybe), and I see no documentation around this. Would I have to reverse engineer a migration script from a manually created permission (would this even work?) or is there an accepted way of doing this?

Actually the documentation is here or here. Creating new roles&permissions can be done any way you want (migration, script). The tables are very simple, they only have these columns:
id
name
created_at
updated_at
So the only thing you need to worry about is entering the name of the role/permission.

Related

Prevent application of a specific database migration in Laravel

I have several database migrations coded in Laravel that I do not want to apply just yet.
I do not want to rename these files or move them into some other folder. If any of the migrations had been applied previously, moving or renaming them breaks Laravel's ability to roll them back.
I do not want a means of applying only one specific migration at a time.
I want a means of marking the class that is a modification to the migration file itself, not some external marking or process (such as adding rows to the migration table).
Is there a programmatic solution for this?
The answer : Laravel 5 - skip migrations may be of help for you, instead of skipping , choose the migrations you want to do directly .
What I'm referring too exactly is the use of caloskao/migrate-specific

Database Migration in TYPO3

I've started to refactor the ext:crawler to make it compatible with TYPO3 9LTS.
Currently we have a domain model based only on a database table + a TCA configuration:
https://github.com/AOEpeople/crawler/blob/master/ext_tables.sql#L48
https://github.com/AOEpeople/crawler/blob/master/Configuration/TCA/tx_crawler_configuration.php
I want to add a regular Domain Model and Repository for the Configurations instead, to benefit more from the code from TYPO3 Core.
My problem is currently:
I don't know how to migrate data from the already existing table tx_crawler_configuration to the new tx_crawler_domain_model_configuration without the users are loosing any data, or need to do any manual work.
I haven't found anything on this topic yet. I know I can "use foreign data source" but it's not foreign data, so not sure this is the best approach.
https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/4-use-foreign-data-sources.html
I appreciate your input, thanks.
Torben Hansen just did something similar, when he migrated sf_bannners from using own Category concept to use the sys_category concept of TYPO3
What he does is creating a ext_update.php script that is being called automatically upon installation. You can see his commit here
https://github.com/derhansen/sf_banners/commit/02c2c6f1729b96940bb4dd0ca29761fe48d28c14
and probably catch him on Slack with any questions

After i change table fields (add or update) in mysql, i really want to recreate all the model and CRUD facility in yii with gii?

Actually, i'm a laravel developer, recently moved to yii and i found gii was there. I can create models, controllers and CRUD facilities with gii... and that's great!
But if I a add more fields in a table or simple delete a field in a table I have to recreate model and controller with gii, otherwise it gives error. It's really taking my time. Is there any other way to do it, because I searched it and found nothing so far about it. People are suggesting command line, but using gii, is it possible?
Why don't you just create a gii model again, once a new field is added.By the looks of it if you do not want to write code again then gii will give an option to modify the existing files and add the fields on its own.Simple as that.
But there is an disadvantage to this,if you have made some modifications as in for logic then that will get overridden once you modify the files using gii.But I suggested this because this fits in your business logic or as far as I can grasp it :p

How to add fields to a model via eloquent in Laravel?

My question is if it is possible to add all the fields directly to a new model via Eloquent.
I guess it would be something like
php artisan make:model MyModel --fields=?
However, I can't find anything related with that. Anyway, I have to generate a lot of model and any trick would be really appreciated.
Thanks in advance
If you mean table's column by fields then:
Firstly you don't need to define fields in modal. I mean in Laravel no need to define fields while creating model. Besides, model automatically work with your database table's columns as its property.
So, now you may want to define columns while creating migration, not while creating model. There is library to serve this demand named as Generator(https://github.com/laracasts/Laravel-5-Generators-Extended) maintained by Laracasts.
Using this generator you can generate migration file to create table in DB specifying their column names and their type also. Here is a example from their Github repo, how you can do this:
php artisan make:migration:schema create_users_table --schema="username:string, email:string:unique"
You can checkout their documentation for more information. Best of luck.
It's not possible with make:model or make:migrations commands, but you can create your own console command and add this feature by yourself.
Also, take a look at source code of make:model and make:migration commands to get some ideas on how to do that.
it looks like only built in options are --migration and -m to include a migration with the model generation. L5.3 Docs
There does look like there is a package for L5.0, which looks like it would work in 5.*+. It is put out by Laracasts:
https://github.com/laracasts/Laravel-5-Generators-Extended
It also looks like you can make a custom solution as well:
https://laracasts.com/discuss/channels/tips/l5-artisan-command-makemodel
Hope that helps!
No options while creating a model,
This is my terminal output (laravel 5.3) while i check,
You don't need to mention fields while creating model.
Ex:- based on the rules you should keep the names as like below,
model name as User
table name as users
then the model automatically handle everything, you don't need to mention the table/fields name.
I was looking for the same thing myself, as I used to work like that in previous frameworks, but could not find it, or at least not as I wanted it, so I did my thing. You can check it out if you like:
https://github.com/Triun/laravel-model-base
It will read your database, and create the laravel eloquent models for you.
It is meant to be very flexible, so the configuration may be a little complex, and I guess that I didnt' catch up with the documentation, but you can ask me if you don't know how to make it do what you want.
Basically it has 4 customization levels:
By out of the box modificators, configurable by the config files.
Including interfaces and traits to your auto-generated models.
Create your own modificators. Classes where you receive the model skeleton before it is saved, so you can add or remove properties, methods, etc.
Generate the model base, but edit yourself the final model.
And, of course, suggestions and contributions are more than welcome.

Better use of models and migration in symfony

Hey.
I'm having a hard time migrating changes I've done i my config/doctrine/schema.yml file.
I added the column age to the user table. Then I did a php symfony doctrine:generate-migrations-diff followed by php symfony doctrine:migrate .
Looking in my database, the column age is now added, without deleting any data.
But, my /lib/model/doctrine/base/BaseUser.class.php is not changed, there is no age field or functions for age . So I also did the command php symfony doctrine:build-model . Finally the model is updated/migrated too.
So I wonder, is this the only way? Seems like a lot of work, and I'm afraid to miss something each time doing it.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
This might be a bad question, but why is the model layer inside the /lib/doctrine path? As far as I have learned, you keep modules inside apps, where you create your view and controller. Why should the model be outside. Like this I can make models without attached controller and view?
Thanks.
Why should the model be outside
Because models can be used everywhere in your project, in example, in different applications and modules.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Of course you can, but migrations are a good approach to track your schema when deploying to production or working in team.
Here how I use doctrine migrations (simple use-case):
Add a column age to my User model in schema.yml
./symfony doctrine:generate-migrations-diff. Migration class(-es) have been generated.
./symfony doctrine:migrate. Column age successfully added to table.
./symfony doctrine:build --all-classes. Build forms/filters/models
That's it. The main idea is that doctrine:generate-migrations-diff class:
Gathers information about all your models' structure (php-representation of schema.yml)
Compares your schema.yml and info from (1)
Generates migration classes based on difference
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
Yes, you can add such method to User model because it's about users.

Categories