msiri
6 months ago

“array_map(): Expected parameter 2 to be an array, int given”

Posted 6 months ago by msiri

I can't handle this error says "array_map(): Expected parameter 2 to be an array, int given" on Laravel 5.8

Basically, I'm trying to create a new record as I've always done, but today get some new error. LOL

This is my controller about store method

 public function store(Request $request)
    {
        $request->validate([
        'deadline' => 'required|date',
        'category' => 'required',
        'title' => 'required|max:255',
        'street_name' => 'required|max:255',
        'street_number' => 'required|numeric',
        'city' => 'required|max:255',
        'chief_town' => 'required|max:255',
        'zipcode' => 'required|numeric',
        'region' => 'required|max:255',
        'country' => 'required',
        'short_description' => 'required|max:255',
        'description' => 'required|max:255',
        'prize_description' => 'required|max:255',
        'prizegiving_description' => 'required|max:255',
        'brief' => 'required|max:255',
        'max_winner' => 'required|numeric',
      ]);

      Opportunity::create($request->all());
      return redirect('/opportunity');
    }

my raw create.blade.php


<form method="post" action="/opportunity">
        <div class="form-group">
            @csrf
            <label for="title">title:</label>
            <input type="text" class="form-control" name="title"/>
            <label for="deadline">deadline :</label>
            <input type="date" class="form-control" name="deadline"/>
            <label for="category">category :</label>
            <input type="text" class="form-control" name="category"/>
            <label for="street_name">street_name :</label>
            <input type="text" class="form-control" name="street_name"/>
            <label for="street_number">street_number :</label>
            <input type="number" class="form-control" name="street_number"/>
            <label for="city">city :</label>
            <input type="text" class="form-control" name="city"/>
            <label for="chief_town">chief_town :</label>
            <input type="text" class="form-control" name="chief_town"/>
            <label for="zipcode">zipcode :</label>
            <input type="number" class="form-control" name="zipcode"/>
            <label for="region">region :</label>
            <input type="text" class="form-control" name="region"/>
            <label for="short_description">short_description :</label>
            <input type="text" class="form-control" name="short_description"/>
            <label for="country">country :</label>
            <input type="text" class="form-control" name="country"/>
            <label for="description">description :</label>
            <input type="text" class="form-control" name="description"/>
            <label for="prize_description">prize_description :</label>
            <input type="text" class="form-control" name="prize_description"/>
            <label for="prizegiving_description">prizegiving_description :</label>
            <input type="text" class="form-control" name="prizegiving_description"/>
            <label for="brief">brief :</label>
            <input type="text" class="form-control" name="brief"/>
            <label for="max_winner">max_winner :</label>
            <input type="number" class="form-control" name="max_winner"/>
        </div>
            <button type="submit" class="btn btn-primary">Create</button>
    </form>

my DB table


public function up()
    {
        Schema::create('opportunities', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->date('deadline');
            $table->string('category')->default('Care', 'Dres', 'Food', 'Home', 'Host', 'Job', 'Talk');
            $table->string('street_name');
            $table->integer('street_number');
            $table->string('city');
            $table->string('chief_town');
            $table->integer('zipcode');
            $table->string('region');
            $table->string('country')->default('Italy');
            $table->text('short_description');
            $table->text('description');
            $table->text('prize_description');
            $table->text('prizegiving_description');
            $table->text('brief');
            $table->integer('max_winner');
            $table->timestamps();
        });
    }

This is the first 20 results of typing Log::info($request->all()); in the controller

#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'array_map(): Ex...', '/Users/MatteoSi...', 92, Array)
#1 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php(92): array_map(Array, 1)
#2 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php(71): Illuminate\Validation\ValidationRuleParser->explodeExplicitRule(1)
#3 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php(49): Illuminate\Validation\ValidationRuleParser->explodeRules(Array)
#4 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(840): Illuminate\Validation\ValidationRuleParser->explode(Array)
#5 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(823): Illuminate\Validation\Validator->addRules(Array)
#6 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(213): Illuminate\Validation\Validator->setRules(Array)
#7 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/Factory.php(151): Illuminate\Validation\Validator->__construct(Object(Illuminate\Translation\Translator), Array, Array, Array, Array)
#8 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/Factory.php(101): Illuminate\Validation\Factory->resolve(Array, Array, Array, Array)
#9 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Validation/Factory.php(136): Illuminate\Validation\Factory->make(Array, Array, Array, Array)
#10 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php(53): Illuminate\Validation\Factory->validate(Array, Array)
#11 [internal function]: Illuminate\Http\Request->Illuminate\Foundation\Providers\{closure}(Array)
#12 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php(110): call_user_func_array(Object(Closure), Array)
#13 /Users/MatteoSiri/Documents/sites/iNvisibili/app/Http/Controllers/OpportunityController.php(68): Illuminate\Http\Request->__call('validate', Array)
#14 [internal function]: Invisibili\Http\Controllers\OpportunityController->store(Object(Illuminate\Http\Request))
#15 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#16 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('store', Array)
#17 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Invisibili\Http\Controllers\OpportunityController), 'store')
#18 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\Routing\Route->runController()
#19 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\Routing\Route->run()
#20 /Users/MatteoSiri/Documents/sites/iNvisibili/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

Please sign in or create an account to participate in this conversation.