Kaustubh
2 years ago

Cant Foreach array in Blade

Posted 2 years ago by Kaustubh

how i can send null data or default value of data from controller here is my code Controller

public function recruiterDet()
{
    $auth = Auth::User()->id;
    $miRec = Recruiters::where('userid',$auth)->first();

    if(!empty($miRec))
    {
        return view('RcDetailMainpage',compact('miRec'));
    }

here i m try to fill some default value so i can foreach it in blade

    else{
        $miRec = collect([['cmpname'=>NULL,'Address'=>NULL],]);
        return view('RcDetailMainpage',compact('miRec'));
    }
}

Blade View

@foreach($miRec as $a)
<input type="text" class="form-control" id="cmpname" name="cmpname" value="{{ $a->cmpname }}">
<input type="text" class="form-control" id="Address" name="Address" value="{{ $a->Address }}">
<input type="submit" value="Update">
@endforeach 

i don't want to use if else condition in blade because i have lots of form if i use if else then it will increase 2 time in size in blade

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