Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

romulo27's avatar

User API

I am developing an api, and on a certain route I need to register a company, but only with the profile 'proponent', how do I get the type of logged in user?

`class ProgramsController extends Controller { /** * @var Programs */ private $programs;

/**
 * ProgramsController constructor.
 */
public function __construct(Programs $programs){

    $this->programs = $programs;
}

public function index(){
    $programs =  Programs::all();
    return response()->json($programs);
}

public function createPrograms(ProgramsRequest $request){
    $perfil = auth()->user();

    return response()->json(
        $this->programs->create($request->all()), 201
    );
}

}`

0 likes
4 replies
nsvetozarevic's avatar

Does users table have type column? In that case Auth::user()->type

1 like
nsvetozarevic's avatar

Did you set the relations in the models? And I suppose profile has name column. If so, you can do if (Auth::user()->profile->name == 'proponent') {....} but I would suggest that you don't keep it as a string, but rather make a constant in Profile Model something like CONST PROFILE_PROPONENT = 'proponent' and then in your controller if (Auth::user()->profile->name == Profile::PROFILE_PROPONENT) {....}

1 like

Please or to participate in this conversation.