Not Able to get Auth::user->id in Laravel
<p>Here is my Controller.</p>

<pre><code>&lt;?php
/**
 * Created by PhpStorm.
 * User: ed
 * Date: 05/02/16
 * Time: 09:33
 */

namespace App\Http\Controllers\API\V1;

use App\Certificate;
use App\Country;
use App\Film;
use App\FilmExtra;
use App\FilmFavourite;
use App\FilmGenre;
use App\FilmLike;
use App\FilmView;
use App\Genre;
use App\Language;
use App\Magazine;
use App\News;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class MagazineController extends ApiController
{
    public function viewAll(){



        echo Auth::user()-&gt;id;
        exit;

        $user_id = Input::get('user_id');

        $magazines = Magazine::paginate(5);
        return parent::api_response($magazines-&gt;toArray(), true, ['return' =&gt; 'all magazines'], 200);
    }

    public function getMagazine($id){
        $magazine = Magazine::find($id);
        if($magazine){
            return parent::api_response($magazine-&gt;toArray(), true, ['return' =&gt; 'magazine details'], 200);
        }else{
            return parent::api_response([], false, ['error' =&gt; 'Couldn\'t find that magazine'], 404);
        }
    }

    protected function getURL($id){
        $magazine = Magazine::find($id);
        if($magazine){
            return parent::api_response(['url' =&gt; $magazine-&gt;file_url], true, ['return' =&gt; 'magazine url'], 200);
        }else{
            return parent::api_response([], false, ['error' =&gt; 'Couldn\'t find that magazine'], 404);
        }
    }

    public function search($term){
        $magazines = Magazine::search($term)-&gt;paginate(5);
        return parent::api_response($magazines, true, ['return' =&gt; 'search for '.$term], 200);
    }

    public function purchased(){

        $magazines = Magazine::leftJoin('ordered_items', 'ordered_items.item_id', '=', 'magazines.id')
                        -&gt;leftJoin('orders', 'orders.id', '=', 'ordered_items.order_id')
                        -&gt;leftJoin('items', 'items.id', '=', 'ordered_items.item_id')
                        -&gt;where('orders.user_id', $user_id)
                        -&gt;where('items.class', 'book');

        if(Input::get('filter')) {
            $jsonFilter = Input::get('filter');
            $filters = json_decode($jsonFilter);

            foreach ($filters as $filter =&gt; $value){
                switch ($filter){
                    case "genre":
                        if($value){
                            $magazines = $magazines-&gt;whereHas('genre', function ($query) use($value) {
                                $query-&gt;whereIn('genre_id', $value);
                            });
                        }
                        break;
                    case "cert":
                       if($value){
                           $magazines = $magazines-&gt;whereIn('cert', $value);
                       }
                        break;
                    case "country":
                        if($value){
                            $magazines = $magazines-&gt;whereIn('country', $value);
                        }
                        break;
                    case "lang":
                       if($value){
                           $magazines = $magazines-&gt;whereHas('languages', function ($query) use($value) {
                               $query-&gt;whereIn('language_id', $value);
                           });
                       }
                        break;
                }
            }


        }

        $magazines = $magazines-&gt;paginate(5);

        return parent::api_response($magazines-&gt;toArray(), true, ['return' =&gt; 'all magazines'], 200);
    }

}
</code></pre>

<p>If i call any of the function for this controller i am not able to get my <code>Auth::user()-&gt;id</code>. </p>

<p>it's throwing an error.</p>

<blockquote>
  <p>ErrorException in MagazineController.php line 54:
  <strong>Trying to get property of non-object</strong></p>
</blockquote>

<p>If i try to echo <code>Auth::user()-&gt;id</code> in any other controller, its working fine.</p>

<p>using <code>laravel 5.2</code></p>

<p>Can anybody help me ? </p>

<p>don't hesitate to ask any question if you want. </p>