App Controller

Creating Controller

Create Laravel Controller file and keep it in your app’s /src/Http/Controller folder.

/packages/vendor-name/project-name/
                    ├── src
                    │   ├── Http
                    │   │   ├── Controllers
                    │   │   │   └── Admin
                    │   │   │       └── AdminDashboardController.php
                    │   │   │   └── User
                    │   │   │       └── UserDashboardController.php
                    │   │   └── Requests

If you set up App route using Route::group suggested on App Routing, you will need to separate controller accordingly.

Admin Controller

    namespace VendorName\ProjectName\Http\Controllers\Admin;

    use App\Http\Controllers\Controller;

    class AdminDashboardController extends Controller
    {
        public function index()
        {
            return view('admin.dashboard');
        }
    }

User Controller

    namespace VendorName\ProjectName\Http\Controllers\User;

    use App\Http\Controllers\Controller;

    class UserDashboardController extends Controller
    {
        public function index()
        {
            return view('user.dashboard');
        }
    }

Request Validation

Create Laravel Request file and keep it in your app’s /src/Http/Requests folder.

/packages/vendor-name/project-name/
                    ├── src
                    │   ├── Http
                    │   │   ├── Controllers
                    │   │   └── Requests
                    │   │   │   └── Admin
                    │   │   │       └── ExampleRequest.php
                    │   │   │   └── User

Here is an example of ExampleRequest:

    namespace VendorName\ProjectName\Http\Requests\Admin;

    use Illuminate\Foundation\Http\FormRequest;

    class ExampleRequest extends FormRequest
    {
        public function authorize()
        {
            return $this->user()->isAdmin();
        }
        public function rules()
        {
            return [
                'attribute-name' => 'required',
            ];
        }

        public function messages()
        {
            return [];
        }
    }