controller example *
* $data = [ * ["name" => "Dashboard1", "url" => route("admin.dashboard")], * ["name" => "Products1", "url" => request()->fullUrl()] * ]; * * populate_breadcumb($data) ** * @param $data * @return void */ function populate_breadcumb($data) { $validated = validate_breadcumb($data); if ($validated["valid"] === true) { view()->composer([ "layouts.admin.app" ], function ($view) use ($data) { $view->with( [ "breadcumbs" => $data ] ); }); } } } if (!function_exists('validate_breadcumb')) { /** * validate breadcumb data * @param $data * @return array */ function validate_breadcumb($data) { $validated = false; $errors = []; foreach ($data as $key => $item) { $messages = [ 'required' => "The :attribute field is required at index: $key.", "url" => "The :attribute format is invalid at index: $key" ]; $validator = Validator::make($item, [ 'name' => 'required', 'url' => "required|url", // "icon" => "" ], $messages); if ($validator->fails()) { $validated = false; $errors[] = $validator->errors(); } else { $validated = true; } } return ["errors" => $errors, "valid" => $validated]; } }