Skip to content

Dependency injection doesn't work like it should on api routes #407

Description

@Dani2kn

Fresh laravel project with only caffeinated install

Create Module User

RouteServiceProvider

` protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require module_path('user', 'Routes/web.php', 'app');
});
}

/**
 * Define the "api" routes for the module.
 *
 * These routes are typically stateless.
 *
 * @return void
 */
protected function mapApiRoutes()
{
    Route::group([
        // 'middleware' => 'auth:api',
        'namespace'  => $this->namespace,
        'prefix'     => 'api',
    ], function ($router) {
        require module_path('user', 'Routes/api.php', 'app');
    });
}`

api.php

Route::apiResource('user', 'UserController')

web.php

Route::resource('user', 'UserController');

UserController.php

/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(User $user) { dd($user); }

on web.php

User {#355 #fillable: array:3 [ 0 => "name" 1 => "email" 2 => "password" ] #hidden: array:2 [ 0 => "password" 1 => "remember_token" ] #casts: array:1 [ "email_verified_at" => "datetime" ] #connection: "mysql" #table: "users" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:8 [ "id" => 1 "name" => "safsg" "email" => "dasfa@fdsg.com" "email_verified_at" => "2019-10-02 00:00:00" "password" => "sgfdfgfdhf" "remember_token" => null "created_at" => null "updated_at" => null ] #original: array:8 [ "id" => 1 "name" => "safsg" "email" => "dasfa@fdsg.com" "email_verified_at" => "2019-10-02 00:00:00" "password" => "sgfdfgfdhf" "remember_token" => null "created_at" => null "updated_at" => null ] #changes: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #visible: [] #guarded: array:1 [ 0 => "*" ] #rememberTokenName: "remember_token" }

on api.php

User {#324 #fillable: array:3 [ 0 => "name" 1 => "email" 2 => "password" ] #hidden: array:2 [ 0 => "password" 1 => "remember_token" ] #casts: array:1 [ "email_verified_at" => "datetime" ] #connection: null #table: null #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: false +wasRecentlyCreated: false #attributes: [] #original: [] #changes: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #visible: [] #guarded: array:1 [ 0 => "*" ] #rememberTokenName: "remember_token" }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions