0

I found that I can create a callback function using view composer

http://laravel.com/docs/responses#view-composers

so how to use class based composer:

View::composer('profile', 'ProfileComposer');

where to place ProfileComposer class?

thanks,

1
  • Do you mean physically or where to call it? Commented May 8, 2014 at 6:39

3 Answers 3

1

The view composer class should be defined as any regular class and might be stored in a libraries folder or if it is only used by a model you might store it there, there is no convention of where to store it. The class can hold some processes you want to reuse and you can register the call in a serviceprovider. This is a great tutorial on how to use it.

http://culttt.com/2014/02/10/using-view-composers-laravel-4/

Sign up to request clarification or add additional context in comments.

Comments

0

You can have that ProfileComposer class inside ProfileComposer.php file and that will be in anywhere you want, if that file is autoloaded. You should be watching a video tutorial about Composers in Laracasts, and it will explain you why we have to use View::composer and how we can use.

Comments

0

I just find the answer in official decumentation.

you can put composer files anywhere in application file system, ex app/composer

and add it to composer.json

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/filters",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/composer"
    ]
},

then run artisan autoload:

php artisan dump-autoload

thanks everybody,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.