jeudi 1 août 2019

Trying to get property of non-object error in hosting, but in local is not error

I'm trying to show my product history like this one in my localhost screenshot in localhost

but when i tried in hosting ended up with an error like this screenshot in hosting

this is my model code

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Transaction extends Model
{
    protected $table = 'transactions';

    public function User(){
      return $this->belongsTo('App\User');
    }

    public function Product(){
      return $this->belongsTo('App\Product');
    }
}

this is my Controller code

        <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use App\Http\Requests;
    use App\Transaction;
    use App\Cart;
    use App\Product;
    use Auth;
    class TransactionController extends Controller
    {
        public function index(){

          $userTransaction = Transaction::where('user_id',Auth::user()->id)->get();
          $userTransactiondate = Transaction::select('created_at')->where('user_id',Auth::user()->id)->first();
          $getpayment = Transaction::select('payment')->where('user_id',Auth::user()->id)->first();

          return view('transaction.history',compact('userTransaction','userTransactiondate','getpayment'));
        }
    }

this is the view code that error

                @foreach ($userTransaction as $u)

                  <tr>
                  <td ><img src="" width="100" height="100" alt=""></td>
                  <td><br></td>
                  <td style="padding-top:30px;"></td>
                  <td> <br>X</td> 
                  <td style="padding-top:30px;"></td>
                  <td><br>=</td>
                  <td style="padding-top:30px;"></td>
                  </tr>
                @endforeach

            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
@endsection

how am i supposed to do with this error? the code is same in localhost and in hosting, thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire