logo
down
shadow

Laravel using Ajax with a View Composer


Laravel using Ajax with a View Composer

By : Steve
Date : November 24 2020, 01:01 AM
To fix this issue View composers are nice, but they are for views. And when you return JSON you don't use views but
code :
return Response::json($data);
$giftbox_items_total = Giftbox::getTotal();


Share : facebook icon twitter icon
Laravel, variable output work with View::share but not with VIew::composer

Laravel, variable output work with View::share but not with VIew::composer


By : Vidhit S
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I think the reason that this isn't working is because of where you put the View Composer in your code. View Composers in Laravel are essentially callbacks that are executed as soon as the view is rendered. Where is this init() function defined? My guess is that the view is being created before your view composer is defined - meaning that the view composer callback will never be executed.
Try moving the whole view composer block from the init() function and append it to the bottom of your routes.php file and see if it works. That's not a bad spot to place your view composers if you do not have too many, if you do you could create a new class to store them in and add that path to your autoload path.
Laravel 5.3 View Composer - Changing data passed from controller to view

Laravel 5.3 View Composer - Changing data passed from controller to view


By : harika
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can do this in view composer only by duplicating a lot of data, so just do this check in Blade template:
code :
@foreach ($plans as $plan)
    ....
    {{ empty($plan->space) ? 'Unlimited' : $plan->space }}
    ....
@endforeach
Understanding Laravel View Composers: Where does my view composer belong?

Understanding Laravel View Composers: Where does my view composer belong?


By : Michael Chin
Date : March 29 2020, 07:55 AM
Hope that helps Citing the answer given by a user in this question:
Difference between boot and register method?
Laravel View Composer Paginating with ajax

Laravel View Composer Paginating with ajax


By : Yasin Jagral
Date : March 29 2020, 07:55 AM
I wish this help you So here is an answer to this question. In case of View Composer Pagination. You can not paginate in composer, you technically have the ability to do that, but even if you get passed of doing requests to the provider(Which is obviously a bad idea) the pagination is still not going to work very well.
One of the basic issues you will face immideatly is pagination the page in a different page like posts/postslug, this one is going to throw errors easly. So what you should do instead is to create a very basic function in controller and do the requests to that page.
code :
$posts = Post::orderBy('created_at', 'desc')
->paginate(15, ["*"], 'sidebar')->withPath('postPaginator');
public function postPaginator(){
$posts = Post::orderBy('created_at', 'desc')->paginate(15 , ["*"], 'sidebar');  
}
if($this->request->ajax()) {
      return [
          'posts' => view('ajax.sidebarindex', ['posts' => $posts])->render(),
          'next_page' => $posts->nextPageUrl(),
      ];
}
Unable to Register View Composer for Laravel Backpack Dashboard View

Unable to Register View Composer for Laravel Backpack Dashboard View


By : user3507299
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Backpack namespaces their views. You can try defining the composer for the namespaced version of the view:
code :
View::composer('backpack::dashboard', ...);
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org