123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- use Illuminate\Support\Facades\Validator;
- if (!function_exists("helper_test")) {
- function helper_test()
- {
- echo "it is working";
- }
- }
- if (!function_exists("populate_breadcumb")) {
-
- 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')) {
-
- 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",
- ], $messages);
- if ($validator->fails()) {
- $validated = false;
- $errors[] = $validator->errors();
- } else {
- $validated = true;
- }
- }
- return ["errors" => $errors, "valid" => $validated];
- }
- }
|