J
J
jazzus2019-01-04 20:39:08
Laravel
jazzus, 2019-01-04 20:39:08

What's wrong with the city variable?

Code in the request file.

public function rules()
    {

      $other_country_id = (new Country)->getId('other_country');

      if (!$this->input('id')) {
          $phone = [
               'phone' => 'required|string|max:30|unique:users,phone'
          ];
      }else{
          $phone = [
               'phone' => 'required|string|max:30'
          ];
      }

      if ($country_id=$this->input('country_id')!==$other_country_id) {
          $city = [
               'city_id' => 'required|integer|nullable|max:10'
          ];
      }
      
      if ($country_id==$other_country_id) {
          $сity = [
               'other_country' => 'required|string|nullable|max:100',
               'other_code' => 'required|string|nullable|max:20',
               'other_city' => 'required|string|nullable|max:100'
          ];
      }

      $websiteAndAddress = [
           'website' => 'url|nullable|max:50',
           'address' => 'string|nullable|max:300'
      ];

      $merge = array_merge($phone, $сity, $websiteAndAddress);

      return $merge;

    }

In the logs, an error Undefined variable: city
Removed all conditions i.e. I leave:
$city = [
               'city_id' => 'required|integer|nullable|max:10'
          ];

- the error has not changed
Started guessing passwords:
removed nullable,
checked the receipt of $other_country_id
connection of the Country model
and still city is not defined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2019-01-04
@jazzus

Put at the very beginning of the function $city = [] ;
And add the line on which it swears. Line number, file, line itself Otherwise
, it can swear at a completely different file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question