Closed ManojKiranA closed 5 years ago
You should check out one of the many online Laravel community sites to help you with this.
There are different ways to add macroable to a class but you have direct access to your model and can add any method you want. Why Macro a class that you have full control of?
Either way, look through the framework to see how Macroable is added. Sometimes it’s not as simple as using the trait.
Next, move this discussion to Laracasts, the Laravel Discord channel, Laravel.io, or the Slack channel.
Hi there,
Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:
Thanks!
i just wanted to know that if that Macroable; trait can be used on model or not
@devcircus I think there are cases which it'll worth to have macroable models. I've opened a feature request, please have a look at it.
Description:
I have Model named as the
Post
and here is itSo After Creating the Scope i have Accesed in the Closure as follows
And the Result is As Expected
select * from
postswhere
post_status= ? and date(
post_created_at) = ?
But in the recent time i have heared the word
Macros
in which enables the user to Write in the own function Within particular class and it can be used so i have created the some of theForm
MacrosSo inside the
boot
method ofAppServiceProvider
i have added my custom form macrosAnd at to namespaces
use Collective\Html\{FormFacade as Form , HtmlFacade as Html};
So i have testted with the closure function
And the result is as expected
But i recently watched on of the tutorials about macros and it Says that macros can be added to any of the Classes not only the classes available in the Laravel Framework
So i have added the
Macroable
to my modelAfter Adding it i have tried to access all the post
I WANT TO KNOW
Does
Macroable
trait can be used in any of class (MODEL ,CONTROLLER ,etc) or on only the laravel core classes