Laravel Sentry limits - laravel

Anybody know how to get limited number of sentry users. I have admin panel in my laravel application and I make a user management. For display data (groups table, user table, permission table, ...) I use jqgrid. So if I have half million users I want to get limited list of users with specific data.
For use limitation in Laravel, I use standard function skip and take, but I cannot use these method on Sentry findAllUsers().
What solution is the best in this case?

There are some ways, one of them is to get an empty Sentry user model, which is based on Eloquent:
$model = Sentry::getUserProvider()->getEmptyUser();
And use it as you would with Eloquent:
$all = $model->all();
$paginated = $model->paginate();
$selected = $model->where('age', '<', 21)->get();

Related

How to update a user using the 'Ion Auth' authentication library in CodeIgniter 4 framework

Below is my code snippet. I want to reduce the balance of a user in the database using Codeigniter 4?
dd($this->ionAuth->update($this->ionAuth->users()->row()->id, ['balance' => 1000]));
*I'm using Ion Auth for updating.
It's just a big burden when updating the database using modelling data.
It looks like you intend to use $this->ion_auth->user() instead of $this->ion_auth->users().
Also keep in mind that executing a dump and die on $this->ion_auth->update(...) returns a boolean not the updated user data.
References:
users() gets all users.
users()
Get the users.
Parameters
'Group IDs, group names, or group IDs and names' - array OPTIONAL. If an array of group ids, of group names, or of group ids and names are passed (or a single group id or name) this will return the users in those groups.
Usage
$users = $this->ion_auth->users()->result(); // get all users
user() gets a single user.
user()
Get a user.
Parameters
'Id' - integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.
Usage
$user = $this->ion_auth->user()->row();
echo $user->email;
look here authentcate library for ci4
https://github.com/lonnieezell/myth-auth
go there download it
ionAuth is not compablitablke with ci4

How to Get Order Details per a single User in Laravel 7

I am making a multi-vendor ecommerce website using Laravel 7. I am trying to make an Order History page where in a single can user can view only his/her own orders. I am having a problem building the query on my OrderHistoryController. These are the codes on my controller:
$users = User::get();
$orders = Order::find($users);
return view('order-history', compact('orders'));
And I'm trying to loop $orders on my blade file. I have:
#foreach ($orders as $order)
<div>{{ $order->id}}</div>
<div>{{ $order->grand_total}}</div>
#endforeach
I am trying to pass the order id and order grand total to my view. I don't get any error however it shows a different order details from a different customer. How do I do this?
You should use MySQL (or any other database you are using) table relationships and foreign keys.
So, your orders table, should have columns id, user_id, date, and so on. The important thing is user_id column. You want to make that column a foreign key. That basically means that user_id will hold an id value from another table, in this case user. See how to make foreign key columns in laravel migrations here.
Next up is to use Laravel's built in model relationships. You can read more about them here. Basically, in your orders model you want to have a function user which returns $this->belongsTo(App\Models\User::class) and in your user model you want to have a function orders which returns $this->hasMany(App\Models\Order::class) (or whatever the namespace is for both of them).
That way, you can call $user->orders and get a collection of Order models which will contain only the orders of that particular user.
Definitely read the documentation carefully and learn basic concepts of the framework first and how relational databases function!
You can get a lot of this information just by googling it or reading the documentation of Laravel or any other framework you plan on using! Good luck learning :)

Don't show the message to all users? ( laravel )

I need to create to send a message to all new users registered on my website. I created a table called messages that admins can store (insert) the messages from the admin panel to this table and these messages are simply shown to all users with a foreach.
I don't know if this the best way to do something like that!
Anyway, the problem is that when any new user register and open his dashboard he just found the old messages
This is the table :
image
And this is the simple code for foreach
$msgForAll = Message::latest()->get();
I'm not sure how to display new messages to the users.
Again the way I made this idea is wrong, I know that ):
You can use eloquent's where spefically the whereDate queries in your case to get certain rows past or before date.
As an example relating to what you want to do, it can be along the lines of this:
// Given that you are using Auth to get the user's data...
// Get messages that were created after the user's creation date
$messages = Message::whereDate('created_at','>',Auth::User()->created_at)->get();

Laravel get values for Authenticated User only

Does laravel provide a more efficient way to only get values for the authenticated user instead of repeating the following line for every model type.
$cards = Auth::user()->cards;
$books = Auth::user()->books;
$friends = Auth::user()->friends;
.........
I can see how this can be accomplished by a middleware but wanted to see if laravel provides anything out of the box.
You can eager load relationships using eloquent's "with" method.

Laravel get all related models for multiple models

I have a users table and a groups table.
I have set up a many to many users/groups relations.
When I run
$users = User::where("id",'=',6)->first()->groups;
,I get the right group.
But I will have cases where my queries will take in an array of users.
How do I get all the groups of all those users using laravel relationships ?
eMAD's suggestion does not work because Laravel only allows relationship functions to be execute on objects and not array of objects. What you want harvey is a concept called eager loading.
$users = User::whereIn('id', [6, 7, 8])->with('groups')->get();
By using this code, you will be able to access $user->groups->someInfo in your code. Happy coding

Resources