L
L
lynnikvadim2015-07-24 02:23:13
Laravel
lynnikvadim, 2015-07-24 02:23:13

Why is an array created?

This code writes an array to the active variable.

public function store(Request $request)
  {
    //dd($request->all());
     
$act= $request->input('active');
        if ($act == 'on') {
   $act='1';
} elseif ($act == null) {
     $act='0';
}  
    $User = new User();
        $User->name = $request->input('name');
        $User->email = $request->input('email');
        $User->password =  $request->input('password') ;
        $User->tel = $request->input('tel');       

        $User->active =  $act;
   dd($User);
        //$User->save();

      
    Flash::success('Пользователь добавлен.');
    return redirect('admin/user');

     }

And at the output I get:
"name" => "3335vfdvd"
"email" => "[email protected]"
"password" => "111"
"tel" => "(555) 555-55-55"
" active" => array:1 [▼
0 => "on"
]
Why is that?
How can you get rid of this?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LittleFatNinja, 2015-07-24
@lynnikvadim

public function store(Request $request)
  {
    //dd($request->all());
     
$act= $request->input('active')[0];
        if ($act == 'on') {
   $act='1';
} else {
     $act='0';
}  
    $User = new User();
        $User->name = $request->input('name');
        $User->email = $request->input('email');
        $User->password =  $request->input('password') ;
        $User->tel = $request->input('tel');       

        $User->active =  $act;
   dd($User);
        //$User->save();

      
    Flash::success('Пользователь добавлен.');
    return redirect('admin/user');

     }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question