title: Laravel ORM Eloquent doesn't work properly on shared hosting but wokrs good on local
body: <p>Here i ve got error <code>Trying to get property 'form' of non-object (View: /home/laravel/web/laravel.swt101.eu/public_html/abonamenty/resources/views/invoices/show.blade.php)</code> in view when i am trying to get value from foreign key, from form model using Laravel's Eloquent. In this line:  <code>{{ $invoice-&gt;form-&gt;form }}</code>. I had several problems with eloquent and have to use DB without Eloquent many times. Same code works fine for another view (proform) it has got same things like invoice, but not gives error on shared hosting. This  <code>{{ $invoice-&gt;form-&gt;form }}</code> in invoices.show view works fine only on local host. I don't know what is going on. Can anybody help me? Please. If there is a problem with server, can anybody help me with how to configurate shared hosting for Laravel Eloquent?</p>
  <p>This is link to shared error. I get this error only on shared hosting. on local it works fine
  <a href="https://flareapp.io/share/x7XVWgma" rel="nofollow noreferrer">https://flareapp.io/share/x7XVWgma</a></p>
  <p>This is my invoice model</p>
  <pre><code>&lt;?php
  
  
  namespace App;
  
  use App\Form;
  use Kyslik\ColumnSortable\Sortable;
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Database\Eloquent\SoftDeletes;
  
  
  class Invoice extends Model
  {
      /**
       * The attributes that are mass assignable.
       *  
       * @var array
       */
      use SoftDeletes;
      use Sortable;
      
  
      
      protected $table = 'invoices';
  
      
      protected $fillable = [
          'invoicenumber', 'invoicedate', 'id', 'selldate', 'user_id', 'paymentmethod', 
          'paymentdate', 'status', 'comments', 'city', 'paid',  'autonumber', 'automonth', 'autoyear', 'name',
           'PKWIU', 'quantity', 'unit', 'netunit', 'nettotal',
           'VATrate', 'grossunit', 'grosstotal', 'form_id', 'currency_id',
      ];
      
      public $sortable = [ 'invoicenumber', 'invoicedate', 'id', 'selldate', 'user_id', 'paymentmethod', 
          'paymentdate', 'status', 'comments', 'city', 'paid',  'autonumber', 'automonth', 'autoyear', 'name',
           'PKWIU', 'quantity', 'unit', 'netunit', 'nettotal',
           'VATrate', 'grossunit', 'grosstotal', 'form_id', 'currency_id',
                         ];
      
      protected $dates = ['deleted_at'];
      public $primaryKey = 'id';
      
  
      
          public function user()
      {
          return $this-&gt;belongsTo('App\User');
      }
  
          public function form()
      {
          return $this-&gt;hasOne('App\Form', 'id', 'form_id');
      }    
  
           public function currency()
      {
          return $this-&gt;hasOne('App\Currency');
      }
     
          public function proform()
      {
          return $this-&gt;belongsTo('App\Proform');
      } 
      
  }
  </code></pre>
  <p>This is my form model:</p>
  <pre><code>    &lt;?php
  
  namespace App;
  use App\Invoice;
  use Kyslik\ColumnSortable\Sortable;
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Database\Eloquent\SoftDeletes;
  
  
  class Form extends Model
  {
      //
       protected $table= 'forms'; 
  
          protected $fillable = [
          'id', 'form', 
      ];
      
          public function invoice()
      {
          return $this-&gt;belongsTo('App\Invoice', 'id', 'form_id');
      }  
      
      
      
          public function proform()
      {
          return $this-&gt;belongsTo('App\Proform');
      }
  }
  </code></pre>
  <p>This is show method of controller:</p>
  <pre><code>    public function show(Invoice $invoice)
      {
          $users = User::all('showname','id');
          $forms = Form::all('id', 'form');
          $currencys = Currency::all('id', 'currency', 'course'); 
          $query = DB::table('forms')
              -&gt;join('invoices', 'forms.id', '=', 'invoices.form_id');
  
          $query1 = DB::table('currencys')
              -&gt;join('invoices', 'currencys.id', '=', 'invoices.currency_id');
        
  /*$invoice2 = Invoice::with('form')-&gt;find($invoice-&gt;id);*/
   $invoice2 = Invoice::find($invoice-&gt;id);     
   $form = $invoice2-&gt;form;
   $invoice-&gt;id;
   /*  dd($invoice2-&gt;form);    */
  
        
  
         
          return view('invoices.show', compact('users', 'forms', 'currencys', 'invoice', 'query', 'query1', 'invoice2'));
          
          
          
      }
  </code></pre>
  <p>This is my show view:</p>
  <pre><code>@extends('layouts.app')
  
  
  @section('content')
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-lg-12 margin-tb&quot;&gt;
              &lt;div class=&quot;pull-left&quot;&gt;
                  &lt;h2&gt;Szczegóły abonamentu&lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class=&quot;pull-right&quot;&gt;
                  &lt;a class=&quot;btn btn-primary&quot; href=&quot;{{ route('invoices.index') }}&quot;&gt; Wstecz&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Numer faktury:&lt;/strong&gt;
                  {{ $invoice-&gt;autonumber }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Kontrahent:&lt;/strong&gt;
                  {{ $invoice-&gt;user-&gt;showname }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Forma płatności:&lt;/strong&gt;
                  {{ $invoice-&gt;form-&gt;form }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Waluta:&lt;/strong&gt;
                  
              &lt;/div&gt;
          &lt;/div&gt;
         &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Data wystawienia faktury:&lt;/strong&gt;
                  {{ $invoice-&gt;invoicedate }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Data sprzedaży:&lt;/strong&gt;
                  {{ $invoice-&gt;selldate }}
              &lt;/div&gt;
          &lt;/div&gt;
                  &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Metoda płatności:&lt;/strong&gt;
                  {{ $invoice-&gt;paymentmethod }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Termin płatności:&lt;/strong&gt;
                  {{ $invoice-&gt;paymentdate }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Miejsce wystawienia:&lt;/strong&gt;
                  {{ $invoice-&gt;city }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Wpłacono:&lt;/strong&gt;
                  {{ $invoice-&gt;paid }}
              &lt;/div&gt;
          &lt;/div&gt;
         &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Status:&lt;/strong&gt;
                  {{ $invoice-&gt;status }}
              &lt;/div&gt;
          &lt;/div&gt;
         &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Uwagi:&lt;/strong&gt;
                  {{ $invoice-&gt;comments }}
              &lt;/div&gt;
          &lt;/div&gt;
               &lt;div class=&quot;pull-left&quot; style=&quot;margin: 15px;&quot;&gt;
                  &lt;h3&gt;Pozycje proformy&lt;/h3&gt;
              &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Nazwa towaru lub usługi:&lt;/strong&gt;
                  {{ $invoice-&gt;name }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;PKWiU:&lt;/strong&gt;
                  {{ $invoice-&gt;PKWIU }}
              &lt;/div&gt;
          &lt;/div&gt;
         &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Ilość:&lt;/strong&gt;
                  {{ $invoice-&gt;quantity }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Jednostka:&lt;/strong&gt;
                  {{ $invoice-&gt;unit }}
              &lt;/div&gt;
          &lt;/div&gt;
                  &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Cena netto jednostki:&lt;/strong&gt;
                  {{ $invoice-&gt;netunit }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Netto razem:&lt;/strong&gt;
                  {{ $invoice-&gt;nettotal }}
              &lt;/div&gt;
          &lt;/div&gt;
         &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Stawka VAT:&lt;/strong&gt;
                  {{ $invoice-&gt;VATrate }}
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Brutto jednostka:&lt;/strong&gt;
                  {{ $invoice-&gt;grossunit }}
              &lt;/div&gt;
          &lt;/div&gt;
         &lt;div class=&quot;col-xs-12 col-sm-12 col-md-12&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;strong&gt;Brutto razem:&lt;/strong&gt;
                  {{ $invoice-&gt;grosstotal }}
              &lt;/div&gt;
          &lt;/div&gt;
  
  
      &lt;/div&gt;
  @endsection
  </code></pre>
  <p>This is all code of invoice controller with show method</p>
  <pre><code>&lt;?php
      
  namespace App\Http\Controllers;
  use Kyslik\ColumnSortable\Sortable;    
  use App\Invoice;
  use Illuminate\Http\Request;
  use App\User;
  use App\Proform;
  use App\Form;
  use App\Currency;
  use DB;     
      
  class InvoiceController extends Controller
  { 
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      function __construct()
      {
           $this-&gt;middleware('permission:product-list|product-create|product-edit|product-delete', ['only' =&gt; ['index','show']]);
           $this-&gt;middleware('permission:product-create', ['only' =&gt; ['create','store']]);
           $this-&gt;middleware('permission:product-edit', ['only' =&gt; ['edit','update']]);
           $this-&gt;middleware('permission:product-delete', ['only' =&gt; ['destroy']]);
      }
      
      public function search4(Request $request)
      {
  
      $user = User::all('showname','id');
      $invoices = Invoice::sortable()-&gt;paginate(5);
          
      $query = DB::table('users')
              -&gt;join('invoices', 'users.id', '=', 'invoices.user_id');
              
          
      $search = $request-&gt;get('search');
      $requestData = ['showname'];
          
      /* $query = Proform::query(); */
      foreach ($requestData as $field){
      $query-&gt;orWhere($field, 'like', '%'.$search.'%');
      }
      $data2=$query-&gt;paginate(5);
      return view('invoices.index', ['invoices' =&gt; $data2, 'user'=&gt; $user])-&gt;with('i', ($request-&gt;input('page', 1) - 1) * 5);
      }
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          $user = User::all('showname','id');
          $invoices = Invoice::sortable()-&gt;paginate(5);
          return view('invoices.index',compact('invoices', 'user'))
              -&gt;with('i', (request()-&gt;input('page', 1) - 1) * 5);
      }
      
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {   
          
          $users = User::all('showname','id');
          $forms = Form::all('id', 'form');
          $currencys = Currency::all('id', 'currency', 'course');
          return view('invoices.create', compact('users', 'forms', 'currencys'));
      }
      
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
  public function store(Request $request)
      {
  
  
  $autoyear = date('Y');
  $automonth = date('m');
  
  $autonumber = DB::table('proforms')
              -&gt;select(DB::raw('MAX(autonumber) as autonumber'))
              -&gt;where('automonth', '=', '$automonth')
              -&gt;where('autoyear', '=', '$autoyear')
              -&gt;get();
  @$auto = @$autonumber[0]-&gt;autonumber;
  @$auto[0]++;
  print_r($auto);
  
  $number = &quot;$auto[0]/$automonth/$autoyear/faktura&quot;;
  
          $validatedData = request()-&gt;validate([
              'invoicedate' =&gt; 'required',
              'user_id' =&gt; 'required',
              'selldate' =&gt; 'required',
              'paymentdate' =&gt; 'required',
              'paymentmethod' =&gt; 'required',
              'status' =&gt; 'required',
              'comments' =&gt; 'nullable',
              'city' =&gt; 'nullable',
              'paid' =&gt; 'nullable',
              'name' =&gt; 'required',
              'PKWIU' =&gt; 'nullable',
              'quantity' =&gt; 'required',
              'unit' =&gt; 'required',
              'netunit' =&gt; 'required',
              'nettotal' =&gt; 'required',
              'VATrate' =&gt; 'required',
              'grossunit' =&gt; 'required',
              'grosstotal' =&gt; 'required',
          ]);
      DB::table('invoices')-&gt;insert([
  ['invoicenumber' =&gt; $request-&gt;invoicenumber,
  'invoicedate' =&gt; $request-&gt;invoicedate,
  'selldate' =&gt; $request-&gt;selldate,
  'user_id' =&gt; $request-&gt;user_id,
  'form_id' =&gt; $request-&gt;form_id,
  'currency_id' =&gt; $request-&gt;currency_id,
  'paymentmethod' =&gt; $request-&gt;paymentmethod,
  'paymentdate' =&gt; $request-&gt;paymentdate,
  'status' =&gt; $request-&gt;status,
  'comments' =&gt; $request-&gt;comments,
  'city' =&gt; $request-&gt;city,
  'autonumber' =&gt; $request-&gt;autonumber,
  'automonth' =&gt; $request-&gt;automonth,
  'autoyear' =&gt; $request-&gt;autoyear,
  'name' =&gt; $request-&gt;name,
  'PKWIU' =&gt; $request-&gt;PKWIU,
  'quantity' =&gt; $request-&gt;quantity,
  'unit' =&gt; $request-&gt;unit,
  'netunit' =&gt; $request-&gt;netunit,
  'nettotal' =&gt; $request-&gt;nettotal,
  'VATrate' =&gt; $request-&gt;VATrate,
  'grossunit' =&gt; $request-&gt;grossunit,
  'grosstotal' =&gt; $request-&gt;grosstotal,
  'autonumber' =&gt; $number, 
  'automonth' =&gt; $automonth, 
  'autoyear'=&gt; $autoyear],
  
  ]);
  
      
          return redirect()-&gt;route('invoices.index')
              -&gt;with('success','Invoice created successfully.');
  }
      
      /**
       * Display the specified resource.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function show(Invoice $invoice)
      {
          $users = User::all('showname','id');
          $forms = Form::all('id', 'form');
          $currencys = Currency::all('id', 'currency', 'course'); 
          $query = DB::table('forms')
              -&gt;join('invoices', 'forms.id', '=', 'invoices.form_id');
  
          $query1 = DB::table('currencys')
              -&gt;join('invoices', 'currencys.id', '=', 'invoices.currency_id');
        
  /*$invoice2 = Invoice::with('form')-&gt;find($invoice-&gt;id);*/
   $invoice2 = Invoice::find($invoice-&gt;id);     
   $form = $invoice2-&gt;form;
   $invoice-&gt;id;
   /*  dd($invoice2-&gt;form);    */
  
        
  
         
          return view('invoices.show', compact('users', 'forms', 'currencys', 'invoice', 'query', 'query1', 'invoice2'));
          
          
          
      }
      
      /**
       * Show the form for editing the specified resource.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function edit(Invoice $invoice)
      {
          $users = User::all('showname','id');
          $forms = Form::all('id', 'form');
          $currencys = Currency::all('id', 'currency', 'course');
          return view('invoices.edit',compact('invoice', 'users', 'forms', 'currencys'));
      }
      
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, Invoice $invoice)
      {
           
              
          
  
              request()-&gt;validate([
              'invoicedate' =&gt; 'required',
              'user_id' =&gt; 'required',
              'selldate' =&gt; 'required',
              'paymentdate' =&gt; 'required',
              'paymentmethod' =&gt; 'required',
              'status' =&gt; 'required',
              'comments' =&gt; 'nullable',
              'city' =&gt; 'nullable',
              'paid' =&gt; 'nullable',
              'name' =&gt; 'required',
              'PKWIU' =&gt; 'nullable',
              'quantity' =&gt; 'required',
              'unit' =&gt; 'required',
              'netunit' =&gt; 'required',
              'nettotal' =&gt; 'required',
              'VATrate' =&gt; 'required',
              'grossunit' =&gt; 'required',
              'grosstotal' =&gt; 'required',
          ]);
      
      /*    $invoice-&gt;update($request-&gt;all()); */
    
          DB::table('invoices')
              -&gt;where('id', $invoice-&gt;id)
              -&gt;update([
  'invoicenumber' =&gt; $request-&gt;invoicenumber,
  'invoicedate' =&gt; $request-&gt;invoicedate,
  'selldate' =&gt; $request-&gt;selldate,
  'user_id' =&gt; $request-&gt;user_id,
  'form_id' =&gt; $request-&gt;form_id,
  'currency_id' =&gt; $request-&gt;currency_id,
  'paymentmethod' =&gt; $request-&gt;paymentmethod,
  'paymentdate' =&gt; $request-&gt;paymentdate,
  'status' =&gt; $request-&gt;status,
  'comments' =&gt; $request-&gt;comments,
  'city' =&gt; $request-&gt;city,
  'autonumber' =&gt; $request-&gt;autonumber,
  'automonth' =&gt; $request-&gt;automonth,
  'autoyear' =&gt; $request-&gt;autoyear,
  'name' =&gt; $request-&gt;name,
  'PKWIU' =&gt; $request-&gt;PKWIU,
  'quantity' =&gt; $request-&gt;quantity,
  'unit' =&gt; $request-&gt;unit,
  'netunit' =&gt; $request-&gt;netunit,
  'nettotal' =&gt; $request-&gt;nettotal,
  'VATrate' =&gt; $request-&gt;VATrate,
  'grossunit' =&gt; $request-&gt;grossunit,
  'grosstotal' =&gt; $request-&gt;grosstotal,
              ]);
          return redirect()-&gt;route('invoices.index')
                          -&gt;with('success','Invoice updated successfully');
      }
      
      /**
       * Remove the specified resource from storage.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function destroy(Invoice $invoice)
      {
       
        /*  $invoice-&gt;delete(); */
              DB::table('invoices')
              -&gt;where('id', $invoice-&gt;id)
              -&gt;update(['deleted' =&gt; 1]);
          
          return redirect()-&gt;route('invoices.index')
                          -&gt;with('success','Invoice deleted successfully');
      }
  }
  </code></pre>