dimanche 24 février 2019

Laravel 5.7.2 Undefined variable in View

I can not get the variable from the controller, if someone can help me will be great. Im working with PHP Laravel 5.7.2.

DetectController.php:

public function store(Request $request){
    if($request->input('Adult_Person') == "on") $checkboxPerson = 1;
    else $checkboxPerson = 0;
    if($request->input('Child') == "on") $checkboxChild = 1;
    else $checkboxChild = 0;

    $detect = \App\Detect::where('user_id', (int)auth()->user()->id);
            if( $detect == NULL ) true;
            else{ 
                $detect = $detect->where('user_id', (int)auth()->user()->id);
                $detect->delete();
                }
            $detect = new \App\Detect;
            $detect->user_id = (int)auth()->user()->id;
            $detect->checkbox_Adult_Person = $checkboxPerson;
            $detect->checkbox_Child = $checkboxChild;
            $detect->save();

            $detect_user[] = $checkboxPerson;
            $detect_user[] = $checkboxChild;

            return view('home',['data' => $detect_user ]);
            //return view('home', compact($detect_user)); //Dont work
            //return view('home')->with('data',$detect_user);  //Dont work

}

home.blade.php:

                    <form method="post" action="">
                    {!! csrf_field() !!}

                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" class="custom-control-input" id="checkbox_Adult_Person" name="Adult_Person"     >
                        <label class="custom-control-label" for="checkbox_Adult_Person">Adult Person</label>
                    </div>
                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" class="custom-control-input" id="checkbox_Child" name="Child"
                        >
                        <label class="custom-control-label" for="checkbox_Child">Child</label>
                    </div>

the web.php

Route::resource('detect', 'DetectController');

Error:

ErrorException (E_ERROR) Undefined variable: detect_user (View: /var/www/html/laravel/test/resources/views/home.blade.php)

Can someone help whith this, Thank!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire