Комментарии:
What is the advantage of using this? Is it better than a helper function?
ОтветитьThe last solution was exactly what I needed for my sidebar. Thanks. :)
Ответитьthanks nice tutorial
Ответитьpublic $categories;
function getCategories() {
if (! $this->categories)
$this->categories = Category::all();
return $this->categories;
}
Thanks so much sir God bless
Ответитьthanks a lot it works
ОтветитьWhat admin ui you are using in this video??
ОтветитьUsing ViewComposers is very useful, I use it, but since I saw the event video I can't stop worrying about traceability and the case when a beginner sees the code, so it can be magical for him if he has no knowledge of ViewComposers.
ОтветитьThanks, that was very helpful
ОтветитьViewComposers Share is little tricky. It should be used only when some data is used on view that is used everywhere. Usually I use it for something that is looped at the app layout (languages / menu items / ...). For 2-3-4 pages I think that it is pointless to use ViewComposers.
Out of that > instead of using private properties as alternative, better make private method that returns what you want. There is no point to overload your constructor with eloquent selection..
Service Injection seems much more traceable way to do this. I think @inject(...) will draw anyone's attention way faster when they need to trace that variable
ОтветитьHey, Povilas. I'd like to see a tutorial about how to override core Laravel classes, or how to override specific methods of core classes. An example would be the debug class which uses Symfony's VarDumper class if I wanted to change the styling of the dd command output. But it could be any core class. A couple of examples about how to implement it so the new functionality is loaded and available by default.
ОтветитьThanks! I wanted to find a way to make my controller functions more clean!
ОтветитьView Composers add global state to the application which makes it a bad solution for projects that are being developed by multiple people. The best solution (imo) for maximized maintainability is using View Models / View Presenters.
ОтветитьHello, I would ask you about Helper Function, Is it doing like compsers?
because it is doing same thing ( pass variable on all project )
Thank you.
I've developing in Laravel for more than a year and I finally found something I didn't know anything about. Thanks
ОтветитьLoad the categories in the constructor is not a good idea because if you have a lot of categories this will increase the load times then the view composers in laravel is a good way but be careful don't abuse remember every data loaded in the views in a normsl scenario comes from database and this suppose infrastructure usement and in the future translated like technical due aka code smell
ОтветитьI am sure this makes 100 logical sense... but to me it feels like more abstraction for abstraction sake.
ОтветитьThis is a cool feature. Thank you for showing!
ОтветитьI am so happy i found your Channel. So good and helpfull!
ОтветитьSir I need help to import date from excel and allocate to 3 different users to perform task. It is data entry project.
ОтветитьHow to acess App\Component\Wrapper class? Without (new SomeWrapperClass())->someMethod() it's impossible to use a class.
ОтветитьI'd say binding variables in ViewComposers will give a lot of questions later on, checking view files and not understanding from where did categories come from.
I'd rather do it Adam Wathan's way, making a small private function in Categories model that returns 3 categories, so in the controller I call it something like Categories::getThreeCagegories() which makes code more clean and readable.
Good reminder, thanks a lot Sir! Take care 👍🏼
ОтветитьGreat video
ОтветитьHi Povilas, I also have faced this kind of scenario when I need to pass languages to all the views I simply wrote view composer in web.php and I achieved the required functionality. I am also going to share code with you and i think this is most simple way to achieve this.
View::composer(['*'], function($view){
$languages = [];
$segments = request()->segments(1);
$queryParams = explode('?', request()->fullUrl());
foreach(cache('LANGUAGES') as $lang) {
$segments[0] = $lang['short_code'];
$languages[$lang['short_code']] = [
'title' => $lang['title'],
'url' => url(implode('/', $segments). ((count($queryParams) > 1) ? '?'.$queryParams[1]:''))
];
}
$view->with('languages', $languages);
});
Sir I need your help for my project can you make a forum from laravel jetstream sir please
ОтветитьHi sir how are you? Sir can you please make a forum on laravel 8 jetstream
ОтветитьI'm so happy that you got well I hope you completely better now
ОтветитьPlease do a video on laravel web-socket using jQuery and bootstrap 4, also a video chat using laravel web-socket and jQuery
ОтветитьYeah, Thank but I know
Ответить