laravel framework service not loading?
巴扎黑
巴扎黑 2017-05-16 12:02:18
0
1
385

I plan to perform some operations before the view is rendered: determine user permissions and display menus, etc.
But now I encountered a problem,
My operation process is:
First in app.php Added to providers:
AppLibrary ViewComposerComposerServiceProvider::class,
Then create a new service provider in the app/Library/ViewComposer directory:
<?php

namespace AppLibraryViewComposer;

use IlluminateSupportServiceProvider;

class ComposerServiceProvider extends ServiceProvider {

/**
 * Bootstrap the application services.
 *
 * @return void
 */
public function boot() {
    // 使用对象型态的视图组件...
    view()->composer(
            '*', 'App\Library\ViewComposer\ViewComposer'
    );

public function register() {

}

}
My service is:
<?php

namespace AppLibraryViewComposer;

use IlluminateContractsViewView;

//use IlluminateHttpRequest;

class ViewComposer {

public function __construct() {
    echo 1111;
    exit;
}

public function compose(View $view) {
    echo 1111;
    exit;
}

}
But I’m at the front desk, and no matter what, I can’t trigger the echo. 1111;In fact, I think my service has not been loaded at all. I deleted all the contents in the app.php file, but the front page can still be displayed normally. The providers array in app.php is not loaded with every request. Is there any reason not to load my ComposerServiceProvider? And why can the page be displayed normally even after deleting the contents of the app.php file?

巴扎黑
巴扎黑

reply all(1)
左手右手慢动作

I just reproduced it according to your description and found that it ran successfully.
According to the poster, if it can still run after deleting the contents in the app.php file, then the poster can try to modify the index.php file and add die in the first line to see if it can run. Personally, I think it is. This situation occurs because the wrong project was modified.
Also, when posting questions in the future, please pay attention to the format specifications. Otherwise it will be difficult to understand.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template