Level 102
Try using a view composer instead
https://laravel.com/docs/8.x/views#view-composers
View::composer('*', function ($view) {
$view->with('cities', City::all());
$view->with('operators', Operator::all())
});
Hi,
When i use View::share('cities', City::all()) in AppServiceProvider.php and try to test with phpunit i got error of cities table missing.
<?php
namespace App\Providers;
use App\Models\City;
use App\Models\Operator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
View::share('cities', City::all());
View::share('operators', Operator::all());
}
}
Try using a view composer instead
https://laravel.com/docs/8.x/views#view-composers
View::composer('*', function ($view) {
$view->with('cities', City::all());
$view->with('operators', Operator::all())
});
Please or to participate in this conversation.