vendredi 17 mai 2019

Error of : Trying to get property of non-object

good day; I create data base helper to reduce my code in laravel frame work , and connect to two data base but when I use function in my helper I receive error message "Trying to get property of non-object ", this is my helper code this is my helper code /**

 * This function Used for get Data For Specific Element.
 */
public static function getDataById($dbName,$tableName,$condition,$data)
{
    $stattment=
        DB::connection($dbName)
            ->table($tableName)
            ->select(['*'])
            ->where($condition, $data)
            ->first();
    return $stattment;
}

this is my controller function

public function all()
{

    $dataView['x']=dBHelper::allData('mysql',
        'products',
        '`status`=? AND `deleted`=?'
        ,array(1,1));

    if(is_object($dataView['x']))
    {
        foreach ($dataView['x'] as $key=>$value):
            $dataView['lang'][$key]=dBHelper::getDataById(
                'mysql2',
                'products',
                'id_product',
                $value->id);
            //var_dump($dataView['lang'][$key]);
        endforeach;
    }

    return view('productss.all',$dataView);
}

this is my view

<div class="content-wrapper">

    <!-- Content Header (Page header) -->

    <section class="content-header">

        <h1>

        </h1>

    </section>

    <!-- Main content -->

    <section class="content">

        <div class="row">

            <div class="col-lg-12">

                <div class="box box-primary">

                    <div class="box-header with-border">

                        <h3 class="box-title ">Show Products</h3>

                    </div>

                    <!-- /.box-header -->

                    <div class="adminform">



                        <!-- form start -->

                        <table id="all_data" class="table table_for_data table-striped table-bordered dt-responsive nowrap tableData" cellspacing="0" width="100%">

                            <thead>

                            <tr>
                                <th>Id</th>
                                <th>User Name</th>
                            </tr>
                            </thead>

                            <tbody>
                            @if(isset($x)&&is_object($x))
                                @foreach($x as $key=>$value)
                                    <tr>
                                    <td></td>
                                    <td></td>
                                    </tr>
                                @endforeach

                            @else
                                <td>no data found</td>
                            @endif

                            </tbody>

                        </table>

                    </div>

                </div>

                <!-- /.box -->

            </div>

        </div>

    </section><!-- /.content -->

</div><!-- /.content-wrapper -->

I recive error when I print

<td></td>

thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire