Hi, I would like to ask for help regarding on passing multiple data or array in View Composer
The error that I encounter is
Trying to get property 'settings_cust_comments' of non-object (View: B:\projects\web\redesign\resources\views\myapps\myapps\index.blade.php)
Please see code below
Thanks in advance
MyComposer.php
<?php
namespace App\Http\View\Composers;
use Illuminate\View\View;
use App\Model\MyApp\SettingsApps;
use App\Model\MyApp\SettingsMainMenu;
use App\Model\MyApp\SettingsSystemCustomerComments;
class RedesignComposer
{
public function compose(View $view)
{
$settings_app = SettingsApps::where('app_name','myapp')->get();
$settings_customer_comments = SettingsSystemCustomerComments::where('active_status','Y')->get();
$menu = SettingsMainMenu::with('submenu')->where('app_id', 'APP001')->get();
$data = array(
'settings_app' => $settings_app,
'settings_cust_comments' => $settings_customer_comments,
'menu' => $menu
);
$view->with('data', $data);
}
}
AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use App\Http\View\Composers\MyAppComposer;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
View::composer([
'auth.*',
'myapps.*'
],
MyAppComposer::class
);
}
}
index.blade.php (Only the portion where I output the $data)
@foreach($data->settings_cust_comments as $customer)
<p class="card-text">{{ $customer->comment }}</p>
@endforeach