1
votes

My Routes:

Route::resource('users/me', 'User\UserController@me');
Route::resource('users', 'User\UserController', ['except' => ['edit', 'create']]);
Route::resource('users.assistants', 'User\UserAssistantController', ['only' => ['index', 'store', 'destroy']]);
Route::resource('users.digital_cases', 'User\UserDigitalCaseController', ['only' => ['index']]);
Route::resource('users.lessons', 'User\UserLessonController', ['only' => ['index']]);

UserController:

<?php

namespace App\Http\Controllers\User;

use App\Transformers\UserTransformer;
use App\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use App\Http\Controllers\ApiController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;

class UserController extends ApiController {
    public function __construct() {
//        parent::__construct();
    }

    public function index(Request $request) {
    }

    public function me() {
        dd('hello');
        return $this->showOne([Auth::user()]);
    }

    public function store(Request $request) {
    }

    public function show(User $user) {
    }    

    public function update(Request $request, User $user) {
    }

    public function destroy(Request $request, $id) {           
    }
}

I want to access me function on POSTMAN. It is a restful API project.

But when I tried to like this, I got an error:

App\Http\Controllers\User\UserController::me@index does not exist.

My laravel version is 5.6.

How can I call me function in UserController using Route on Postman

1

1 Answers

4
votes

Replace:

Route::resource('users/me', 'User\UserController@me');

With:

Route::get('users/me', 'User\UserController@me');

Why? resource is a shortcut for a list of HTTP verbs and a list of method in a controller.