where do I apply logic code for user registration in laravel - laravel

I'm using custom registration in Laravel.
In register.blade.php the user gives the following data
$data['User_name','User_Coll_name','Branch_name','email','password']
And I want to create new user with Class_id
$class= DB::select('select * from classes where College_id = ? And Branchc_id = ? ',[$data['User_Coll_name'],$data['Branch_name']]);
I'm new to laravel please help me, where do I apply above logic. And also how to create new class if doesn't exist
$class = new class();

I can think of two ways of doing this.
1) In App/Http/Controllers/Auth/RegisterController.php, there is a create method. You can add your logic to create a new class and associate it with the user in this method.
2) My favorite way of doing it is by using Events & Listeners. So each time somebody has registered, you can fire the event and then through the listener, you do the appropriate logic.

Related

How to call a laravel factory dynamically?

I have the following seeder.
User::factory(100)
->has(Loan::factory()->count(5))
->has(Transaction::factory()->count(5)
->has(TransactionDetail::factory()->count(1), 'transaction_detail'))
->create();
Now I want to call another Verification class based on a verified property in the User class. So verified could have three possible values - 'pending', 'unverified', 'verified'. Now when it's verified or pending, I want to create a Verification class. But when it's unverified, I don't want to call that class. Something like this...
User::factory(100)
->($user->verified !== 'unverfied') ? has(Verification::factory()) : null
->has(Loan::factory()->count(5))
->has(Transaction::factory()->count(5)
->has(TransactionDetail::factory()->count(1), 'transaction_detail'))
->create();
Now, I know this syntax doesn't make any sense. But I am just trying to explain my problem.
How do I call this verification factory based on $user->verified?
Thanks in advance.

How to add custom Models Rocket Chat

I am trying to add new models to RocketChat specifically to store Location information. I have extended the models._Base model to ModelLocations and assigned it to RocketChat.models.Locations as following
RocketChat.models.Locations = new ModelLocations('location', true);
But when I try to use RocketChat.models.Locations it's always undefined. I observed the migrations folder and thought I need to create a migration file but I couldn't find documentation for that. Can anybody point me on how to add a new model.
I forgot to add the new model's file path in Rocket.Chat/packages/rocketchat-lib/package.js. Once added it works.

How do I call the core content component in my custom component in joomla 2.5?

My custom component has to call the core content component and create an entry in the #__content table with proper values. When I add a new article in the article manger I have to give only a title as mandatory field value and other values will be created automatically. I want to pretend this in my custom component.
Instead of updating the database table directly load the ContentModelArticle from com_content and use the model to create new articles. This will generate the alias for you, do all of ACL etc based on the View Access and let any system or content plugins have a look at the article and do whatever they do.
ContentModelArticle extends from JModelAdmin so you can use it's ->save($data) method. Where $data is the array of content to bind to the new ContentModelArticle in the save() method.
So, a basic example would be :
// Create our data with some sample code
$data['title'] = 'My Title';
$data['catid'] = 10; /* NB. this is just an example category Id obviously you'll need to provide a suitable catid for your site */
$data['articletext'] = 'Starting text...'; /* From memory you can't have an empty article.*/
// Get the Article model
$articleModel = $this->getModel('Article', 'ContentModel', array());
// Then save it:
$articleModel->save($data);
Obviously you can populate as many fields as you want, including state, publish_up, publish_down, create_by and lots of others — just look at the structure of the content table in the database #__content to see the various columns and their type.
NB: This is untested code just typed into the browser. It's also been a while since I did any 2.x stuff.
Finally, as this question is about Joomla specific implementation details, you may get a better result if you, try asking on the Joomla Q&A StackExhange site

Sentry & Laravel, getting users within a group. changing findAllUsersWithAccess to have pagination

I'm trying to find all users w/ a specific permissions list in Sentry with laravel. The problem is that Sentry::findAllUsersWithAccess() returns an array().
as stated in their github repository i pinpointed their code to be
public function findAllWithAccess($permissions)
{
return array_filter($this->findAll(), function($user) use ($permissions)
{
return $user->hasAccess($permissions);
});
}
right now, it gets all users and filter it out with users with permission list. the big problem would be when I as a developer would get the set of users, it'll show ALL users, i'm developing an app which may hold thousands of users and i only need to get users with sepcific permission lists.
With regards to that would love to use one with a ->paginate() capability.
Any thoughts how to get it without getting all the users.
Why dont you override the findAllWithAccess() method and write your own implementation, which uses mysql where instead of array_filter().
I dont know your project structure and the underlying db schema, so all i can give you atm is the link to the eloquent documentation Querying Relations (whereHas).
In case you dont know where to start: its always a good idea to look at the ServiceProvider (SentryServiceProvider, where the UserProvider, which holds the findAllWidthAccess() method, is registered). Override the registerUserProvider method and return your own implementation of the UserProvider (with the edited findAllWithAccess() method).
Hope that will point you in the right direction.
In Laravel you can do pagination manually on arrays:
$paginator = Paginator::make($items, $totalItems, $perPage);
Check the docs: http://laravel.com/docs/pagination

get joomla registration form variables?

I'm working on getting joomla registration form values that user enters
at the time of registration. After two days of searching I reached to the
file Joomla2.5.7\components\com_users\controllers\registration.php. In the register() method I
tried to echo $data and $requestData variables but didn't see any output, on registering a new entry. I also tried to echo javascript but was unsuccessful. I'm trying to connect joomla database with my own database, so that whenever new user registers , he is also registered to my website. How can I get the registration form variables, any kind of help is really appreciated.
Ty this
On registration controller you can find a function call to model like this
$return = $model->register($data);
after that just
echo "<pre/>";
print_r($data);
Also in the registration model
components\com_users\model\registration.php
register() method is defined you can check that for more info.
In addition if you want to add the users info to the other DB like your website DB.
The best place to write mysql query is :
// Store the data.
if (!$user->save()) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}else{
//Your custom mysql query to other DB or tables
}
find the above section in the registration model inside register()method.
Hope this may solve your problem..
I hope this tutorial helps you. You will find it explains the process of joomla registration form very well.
http://youtu.be/2AyCzb2vTaU

Resources