I have a problem with laravel. I need to create two class like that :
Class Users {}
Class Companies extends Users {}
It's an inheritance relationship. And this is my database :
And I don't know how to create the model User and Companies in Laravel. And how to use them.
Can you help me ?
Thank you by advance !!
If you are using artisan then things would be as simple a typing the following command in your terminal, giving that your pwd is your project directory:
php artisan make:model User
This will create a User.php file that is a class named User, and inherits from Model.php, eloquent's model class.
If you want to create a model and also create a table in the database with certain columns, you can use the --migration argument with the previous command, for instance:
php artisan make:model User --migration
After running this command, you'll have to open database/migrations and modify the file created as you wish to create your table.
If you do not use artisan -then you should be- you can just create the model manually by creating a new class in a file that extends from eloquent's model.
For instance:
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
}
And that should be it.
For further reading, consult Laravel's documentation, it contains all your basic questions such as the one you have just asked.
For the link to the documentation about Models, clikc here
Related
I have an app within my wagtail site which uses several pages constructed in views.py (here because they contain complex-ish processing of forms and data and do not need any CMS functionality). One of these views, I want to restrict to users of a specific group.
For other pages, I use a #logon required mixin, which works fine. I can write some code which uses something like def has_group(user, group_name):
return user.groups.filter(name=group_name).exists(), but this seems messy when wagtail has a nice built in permissions model. Therefore, I am trying to use the following hook in wagtail_hook.py:
from django.contrib.auth.models import Permission
from wagtail.core import hooks
#hooks.register('register_permissions')
def view_committee_page():
return Permission.objects.filter(codename="view_committee_page")
This isn't showing up in wagtail admin under group object permissions as I believe it should.
My understanding is only based on the odd example I've found using Wagtail v1.X. The documentation is vague on this specific hook: https://docs.wagtail.io/en/v2.5.1/reference/hooks.html#register-permissions
The only modification I've made to the examples I've seen (eg. here: Wagtail set additional permissions for MyPage ) is to update wagtail.wagtailcore to wagtail.core as per 2.0 release notes.
I know my wagtail_hooks.py file is being picked up correctly as I have another hook in there working as expected.
Am I missing something? Is there a more up to date way to solve this problem?
How about creating your own function with the decorator:
#hooks.register('before_serve_page')
in watail_hooks.py there is a function called check_view_restrictions() so you could do something similar to this?
You would also need to set the permissions on your Page model.
from wagtail.core.models import Page
class MyPage(Page):
class Meta:
permissions = (("page_view_only", "Can view my pages"),)
Then use the hook in wagtail_hooks.py
from django.contrib.auth.models import Permission
from wagtail.core import hooks
#hooks.register('register_permissions')
def page_view_only():
return Permission.objects.filter(codename="page_view_only")
There should be a new permission available in the admin Group settings.
How can i rename my Apex class?
For example if I want to change the name of my apex class from ABC to ABC123, how can I do that?
If you wanted to do it through a metadata deployment, your only option would be to delete the old class and create a new one.
In the ui (Setup > Develop > Apex Classes), you can change the class name, but it won't change any of the references, so if you don't manually change all references to the class, you might start getting errors that say:
Dependent class is invalid and needs recompilation
Renaming a class in the ui will associate a different name with the same salesforce id for the class, so there is a subtle difference between that and deleting and creating a new class.
there are 3 ways to rename Apex Classes
Using Force.com, follow this link
https://developer.salesforce.com/page/Miscellaneous
or
Force.com IDE didn't reflect my changes?
Using mavenmate
https://salesforce.stackexchange.com/questions/61405/how-to-rename-class-in-mavensmate
Salesforce CLI
In VS code login using Salesforce CLI and rename the apex class and its reference by find & replace class Name. and
Rename the class in apex class folder to new name and deploy to org
after that you can see 2 classes old class and new Class with same content delete the old class
Using CakePHP 2.6.7
When baking a normal part of an application (e.g. using cake bake model) the console is interactive - it goes through the construction process asking for you to choose options at each stage.
But when using cake bake model MyModel --plugin MyPlugin to do the same for a plugin no options are displayed and it generates the model in the plugin folder using default settings.
Is there a way to make the generation of the individual parts of a plugin interactive in the same manner? (this goes for model/controller/view)
When a model in a plugin is baked using cake bake model MyModel --plugin MyPlugin it uses scaffolding. To avoid this you have to use cake bake model --plugin MyPlugin and then the first option presented will allow you to choose from the possible models to be baked.
Replace model with controller/view as appropriate to bake those as well.
I'm sure there is a relatively simple answer. I am trying to use CakePHP 2.0 to bake an application from the command line, and i would like cake to create the basic AuthComponent methods for my user model. the database table for users is named users, which includes the two necessary fields for auth, username and password.
I've been able to include AuthComponent in my usersController from bake, but have been unsuccessful at getting it to generate basic usersController actions for auth, such as login() and logout().
How can I do this? generating this skeleton code will help save a lot of time.
Thanks in advance!!!!
default bake templates are only for CRUD (create=add, read=index,view update=edit, delete=delete), not for the rest. but it is fairly simple to customize your templates according to your needs.
Although login/logout are one-time-needed methods and don't make any sense to be baked. Its easier and faster to just manually "make" them. For login use the add template as basis, logout doesnt need any view.
Using cake 2.1.1. I'm trying to make a cron job to execute an action from a controller. Which is right way to do this? I have the OffersController with an action called admin_test. I'd wish to run this action every 2 hours. For the moment I made a shell in app/Console/command/SyncapiShell.php:
class SyncapiShell extends AppShell {
public $uses = array('Offer');
public function main() {
$this->Offer->admin_test();
}
}
But I get a SQLSTATE[42000] Syntax error or access violation trying to execute the shell.
I'm also using the admin routing, the auth component and ACL. How does the shell work? It ignores the authentication and the acl rights? Normally the admin_test action may be accessed only by specific authenticated users.
Thank you
No this is not the right way to do but more likely a strong indicator that your app architecture is not good. You should have fat models and tiny controllers.
Shell:uses will work like the uses property of a controller and load models. In Controllers you should use the model associations and not load thousands of models using uses.
Refactor your controller method and move the code into the Offer model.
And why does a shell need authentication or admin routing? A shell is, as the name says, a shell program, NOT a website. Authentication is basically done by the OS and user who runs the script. Only people who have access to the shell will have be able to run it anyways.