Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dani2kn opened this issue Oct 2, 2019 · 0 comments
Open

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

Dani2kn opened this issue Oct 2, 2019 · 0 comments

Comments

@Dani2kn
Copy link

Dani2kn commented Oct 2, 2019

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" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant