Taylor has outlined a spot in the Spark documentation where you can modify the return of the global user object. It says that you can use to change it:
Spark::swap('UserRepository@current', function () {
// Return the current user...
});
Here is what I have so far:
Spark::swap('UserRepository@current', function () {
$user_id = Auth::user()->id;
if (Auth::user()->type == 1) {
// is an employer
Auth::user()->jobs = User::find($user_id)->employer->jobs->toArray();
return Auth::user();
}
});
This will show correctly when I dd it right after the query, but will not show when I call dd(Auth::user()) globally.
Any info on this process would be awesome. Thanks!
@EventFellows , I'm still having a hard time getting the data to stay in the user object. Would you mind sharing your code that you put into your SparkServiceProvider? Here is what I have so far:
Spark::swap('UserRepository@current', function () {
$user_id = Auth::user()->id;
if (Auth::user()->type == 1) {
/**
* is employer
*/
Auth::user()->jobs = User::find($user_id)->employer->jobs->toArray();
return Auth::user();
}
});
I'm having the same issue where if I add it with the swap, it will show when I dd it right after the query, but it still does not want to actually show in the global scope. I have no clue.
If anyone has actually done this and could pass their example, that would be awesome. Thanks!